RosettaCodeData/Task/Binary-search/OCaml/binary-search.ocaml
Ingy döt Net d066446780 langs a-z
2013-04-10 22:43:41 -07:00

13 lines
333 B
Text

let rec binary_search a value low high =
if high = low then
if a.(low) = value then
low
else
raise Not_found
else let mid = (low + high) / 2 in
if a.(mid) > value then
binary_search a value low (mid - 1)
else if a.(mid) < value then
binary_search a value (mid + 1) high
else
mid