RosettaCodeData/Task/Binary-search/Pop11/binary-search-2.pop11
Ingy döt Net d066446780 langs a-z
2013-04-10 22:43:41 -07:00

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;