RosettaCodeData/Task/Binary-search/MATLAB/binary-search-3.m
Ingy döt Net 6f050a029e update
2013-06-05 21:47:54 +00:00

20 lines
342 B
Mathematica

function mid = binarySearchIter(list,value)
low = 1;
high = numel(list) - 1;
while( low <= high )
mid = floor((low + high)/2);
if( list(mid) > value )
high = mid - 1;
elseif( list(mid) < value )
low = mid + 1;
else
return
end
end
mid = [];
end