mirror of
https://github.com/heqin-zhu/algorithm.git
synced 2024-03-22 13:30:46 +08:00
8 lines
373 B
Haskell
8 lines
373 B
Haskell
|
search i li= binary 0 $length li -1
|
||
|
where binary a b= let mid = div (a+b) 2
|
||
|
p = li!!mid
|
||
|
in if a>=b then a
|
||
|
else if p==i then mid
|
||
|
else if p>i then binary a $mid-1
|
||
|
else binary (mid+1) b
|