Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2010
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.71 KB | None | 0 0
  1. function bsearch( $findwhat, $inwhat ) {
  2.     $min = 0;
  3.     $max = count( $inwhat ) - 1;
  4.     // /* I forgot this before testing
  5.     if ( $max == $min )
  6.         return false;
  7.     // */
  8.     do {
  9.         $halfway = floor( ( $max - $min ) / 2 ) + $min;
  10.         if ( $inwhat[$halfway] == $findwhat )
  11.             return true;
  12.         if ( $inwhat[$halfway] > $findwhat )
  13.             $max = $halfway;
  14.         if ( $inwhat[$halfway] < $findwhat )
  15.             $min = $halfway + 1;
  16.         if ( $min == $max ) {
  17.             // /* I forgot this before testing
  18.             if ( $inwhat[$min] == $findwhat )
  19.                 return true;
  20.             // */
  21.             return false;
  22.         }
  23.     } while( true );
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement