daily pastebin goal
81%
SHARE
TWEET

Untitled

a guest Jun 14th, 2018 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public function binarySearch($arr, $item) {
  2.         $low = 0;
  3.         $hight = count($arr) - 1;
  4.        
  5.  
  6.         while ($low <= $hight) {
  7.             $mid = $low + $hight;
  8.             $guess = $arr[$mid];
  9.             if ($guess == $item) {
  10.                 return $mid;
  11.  
  12.             } elseif ($guess > $item) {
  13.                 $hight = $mid - 1;
  14.             } elseif ($guess < $item) {
  15.                 $low = $mid + 1;
  16.             }
  17.         }
  18.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top