<?php
function sorted($a){
$l = 0;
for ($i=0; $i<count($a); $i++){ if ($a[$i] <= $med) $l++;
if ($a[$i] >= $med) $r--;
if ($l == $r) break;
$al = $a[$l];
if ($a[$l] > $a[$r]){
$a[$l] = $a[$r];
$a[$r] = $al;
}
}
return sorted($a);
}
$a = array(11,1,23,45,7,12,4,6,8,43);
PD9waHAKCWZ1bmN0aW9uIHNvcnRlZCgkYSl7CgkJJGwgPSAwOwoJCSRyID0gY291bnQoJGEpLTE7CgkJJG1lZCA9ICRhW3JvdW5kKCRyLzIpXTsKCQoJCWZvciAoJGk9MDsgJGk8Y291bnQoJGEpOyAkaSsrKXsKCQkJaWYgKCRhWyRpXSA8PSAkbWVkKSAkbCsrOwoJCQlpZiAoJGFbJGldID49ICRtZWQpICRyLS07CgkJCWlmICgkbCA9PSAkcikgYnJlYWs7CgkJCgkJCSRhbCA9ICRhWyRsXTsKCQkKCQkJaWYgKCRhWyRsXSA+ICRhWyRyXSl7CgkJCQkkYVskbF0gPSAkYVskcl07CgkJCQkkYVskcl0gPSAkYWw7CgkJCX0KCQl9CgkJcmV0dXJuIHNvcnRlZCgkYSk7Cgl9CgkKCSRhID0gYXJyYXkoMTEsMSwyMyw0NSw3LDEyLDQsNiw4LDQzKTsKCXByaW50X3Ioc29ydGVkKCRhKSk7