fork download
  1. <?php
  2. function quickSort($startID,$endID) {
  3. global $a;
  4. $pivot = $a[(int)(($startID + $endID)/2)];
  5. $left = $startID;
  6. $right = $endID;
  7. while (true) {
  8. while ($a[$left] < $pivot) {
  9. $left++;
  10. }
  11. while ($pivot < $a[$right]) {
  12. $right--;
  13. }
  14. if ($right <=$left) {
  15. break;
  16. }
  17. $tmp = $a[$left];
  18. $a[$left] = $a[$right];
  19. $a[$right] = $tmp;
  20. $left++;
  21. }
  22. if ($startID < $left-1) {
  23. quickSort($right+1,$endID);
  24. }
  25. }
  26. $a = array(10,3,1,9,7,6,8,2,4,5);
  27. quickSort(0, count($a)-1);
  28. print_r($a);
  29. ?>
  30.  
Success #stdin #stdout 0.03s 25812KB
stdin
Standard input is empty
stdout
Array
(
    [0] => 5
    [1] => 3
    [2] => 1
    [3] => 4
    [4] => 2
    [5] => 6
    [6] => 7
    [7] => 8
    [8] => 9
    [9] => 10
)