if ( target < thing[first] || target > thing[last] )
return( NOT_FOUND );
while ( first < last ) {
mid = ( first + last ) / 2; /* truncate to integer */
if ( target == thing[mid] )
return( mid );
if ( target < thing[mid] )
last = mid - 1;
else
first = mid + 1;
}
if ( target == thing[last] )
return( last );
return( NOT_FOUND );
|