Guest User

Untitled

a guest
Jun 14th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  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. }
Add Comment
Please, Sign In to add comment