RosettaCodeData/Task/Binary-search/Icon/binary-search-1.icon
Ingy döt Net db842d013d A-M baby
2013-04-10 21:29:02 -07:00

11 lines
280 B
Text

procedure binsearch(A, target)
if *A = 0 then fail
mid := *A/2 + 1
if target > A[mid] then {
return mid + binsearch(A[(mid+1):0], target)
}
else if target < A[mid] then {
return binsearch(A[1+:(mid-1)], target)
}
return mid
end