13 lines
496 B
Text
13 lines
496 B
Text
binary_search_rec(A, Value) = Ret =>
|
|
Ret = binary_search_rec(A,Value, 1, A.length).
|
|
|
|
binary_search_rec(A, _Value, _Low, _High) = -1, sort(A) != A => true.
|
|
binary_search_rec(_A, _Value, Low, High) = 0, High < Low => true.
|
|
binary_search_rec(A, Value, Low, High) = Mid =>
|
|
Mid1 = (Low + High) // 2,
|
|
if A[Mid1] > Value then
|
|
Mid1 := binary_search_rec(A, Value, Low, Mid1-1)
|
|
elseif A[Mid1] < Value then
|
|
Mid1 := binary_search_rec(A, Value, Mid1+1, High)
|
|
end,
|
|
Mid = Mid1.
|