Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function bsearch( $findwhat, $inwhat ) {
- $min = 0;
- $max = count( $inwhat ) - 1;
- // /* I forgot this before testing
- if ( $max == $min )
- return false;
- // */
- do {
- $halfway = floor( ( $max - $min ) / 2 ) + $min;
- if ( $inwhat[$halfway] == $findwhat )
- return true;
- if ( $inwhat[$halfway] > $findwhat )
- $max = $halfway;
- if ( $inwhat[$halfway] < $findwhat )
- $min = $halfway + 1;
- if ( $min == $max ) {
- // /* I forgot this before testing
- if ( $inwhat[$min] == $findwhat )
- return true;
- // */
- return false;
- }
- } while( true );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement