有人能告訴我這裏的錯誤在哪裏?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