Advertisement
Guest User

Quick sort median pivot

a guest
May 3rd, 2014
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.34 KB | None | 0 0
  1.    function selectPivot(array $array)
  2.    {
  3.       $x      = $array[0];
  4.       $y      = $array[(int)(count($array)/2)];
  5.       $z      = $array[count($array)-1];
  6.       if($x>=$y)
  7.       {
  8.          if($y>=$z)
  9.             return $y;
  10.          return $x>=$z?$z:$x;
  11.       }
  12.       if($x>=$z)
  13.          return $x;
  14.       return $y>=$z?$z:$y;
  15.    }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement