How does php implement fast sorting? Function & nbsp; quick (& amp; $ arr, $ low, $ high) {& nbsp; $ key & nbsp; $ low; & nbsp; for ($ I $ low, $ j $ high; $ I! How does php implement fast sorting?
function quick(&$arr,$low,$high){
$key = $low;
for($i=$low,$j=$high;$i!=$j;){
for(;$j>$key;){
if($arr[$j]<$arr[$key]){
list($arr[$j],$arr[$key])=swap($arr[$j],$arr[$key]);
$key = $j;
break;
}else{
$j--;
}
}
for(;$i<$key;){
if($arr[$i]>$arr[$key]){
list($arr[$i],$arr[$key])=swap($arr[$i],$arr[$key]);
$key = $i;
break;
}else{
$i++;
}
}
}
if($high>$low){
quick($arr,$low,$key-1);
quick($arr,$key+1,$high);
}
}
$arr = array(7,4,9,1,3,2,6,8,0);
quick($arr,0,8);
print_r($arr);
If it is not recursive, it is normal to run it once (remove the if ($ high> $ low) section ). A recursion won't work. Chrome has been turning around for half a day. it should be infinite recursion. Where is the problem?
Php algorithm express sorting
------ Solution --------------------
Seeing Venus in my eyes