Anonymous
public text v1 · immutableBinarySearch( A, value ) {
low = 0
high = N + 1
p = (high+low)/2 //Initial probe position
while ( low < high ) {
if ( A[p] > value )
high = p
else if ( A[p] < value ) //Wasteful second comparison forced by syntax limitations.
low = p
else
return p
//
// this can fail for large numbers, see reference to the Google blog,
// or the discussion page about integer overflow & how the fix to handle this.
//
p = (high+low)/2 //Next probe position.
}
return not_found
}