RosettaCodeData/Task/Binary-search/Maple/binary-search-2.maple

18 lines
522 B
Plaintext

BinarySearch := proc( A, value )
description "iterative binary search";
local low, high;
low, high := ( lowerbound, upperbound )( A );
while low <= high do
local mid := iquo( low + high, 2 );
if A[ mid ] > value then
high := mid - 1
elif A[ mid ] < value then
low := mid + 1
else
return mid
end if
end do;
FAIL
end proc: