16 lines
395 B
Text
16 lines
395 B
Text
define BinarySearch(A, value);
|
|
define do_it(low, high);
|
|
if high < low then
|
|
return("not_found");
|
|
endif;
|
|
(low + high) div 2 -> mid;
|
|
if A(mid) > value then
|
|
do_it(low, mid-1);
|
|
elseif A(mid) < value then
|
|
do_it(mid+1, high);
|
|
else
|
|
mid;
|
|
endif;
|
|
enddefine;
|
|
do_it(1, length(A));
|
|
enddefine;
|