有人能告诉我这里的错误在哪里?OCaml中的二进制搜索?
let a = [|2;4;6;9;12|];;
a.(0);;
a.(4);;
a.(5);;
let binary_search array size x =
let n = size-1 in
let p = ref 0 in
let r = ref n in
while (!p <= !r) do
let q = (!p + !r)/2;
if array.(q) = x
then raise ((Found_It (q));)
else if (array.(q) <> x) && (array.(q) > x)
then (r := q - 1;)
else if array.(q) < x
then (p := q + 1;)
done;
else -1;;
exception Found_It of int;;
如果您对ocaml中的二进制搜索有任何建议,请通知我?
这与*** Emacs ***有什么关系?如果答案看起来像* nothing,那么考虑从标题中删除标签'emacs'和“emacs”。 – Drew