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