fork(1) download
  1. <?php
  2. function sorted($a){
  3. $l = 0;
  4. $r = count($a)-1;
  5. $med = $a[round($r/2)];
  6.  
  7. for ($i=0; $i<count($a); $i++){
  8. if ($a[$i] <= $med) $l++;
  9. if ($a[$i] >= $med) $r--;
  10. if ($l == $r) break;
  11.  
  12. $al = $a[$l];
  13.  
  14. if ($a[$l] > $a[$r]){
  15. $a[$l] = $a[$r];
  16. $a[$r] = $al;
  17. }
  18. }
  19. return sorted($a);
  20. }
  21.  
  22. $a = array(11,1,23,45,7,12,4,6,8,43);
  23. print_r(sorted($a));
Runtime error #stdin #stdout 0.24s 86592KB
stdin
Standard input is empty
stdout
Standard output is empty