, : length = 0, , , , (.. `(low + high)/2 ' ), , ..
, , , :
bool search(int[] array, int length, int valueToFind)
{
int pos=0;
int limit=length;
while(pos<limit)
{
int testpos = pos+((limit-pos)>>1);
if (array[testpos]<valueToFind)
pos=testpos+1;
else
limit=testpos;
}
return (pos < length && array[pos]==valueToFind);
}
, , , , 2. , , , , , , , , , .
, testpos
, , pos <= testpos < limit
, AND , .
, , , high<low
. , pos==limit
, ..
, ", x, , xs, ", " x ", " x " ..