php快速排序
<?php
function quick_sort($arr){
$count = count($arr);
if($count<=1){
return $arr;
}
$left = array();
$right = array();
$key = $arr[0];
for($i=1;$i<$count;$i++){
if($arr[$i]<$key){
$left[] = $arr[$i];
}else{
$right[] = $arr[$i];
}
}
$left_arr = quick_sort($left);
$right_arr = quick_sort($right);
$quick_arr = array_merge($left_arr,array($key),$right_arr);
return $quick_arr;
}
$array = array(2,3,1,5,7);
print_r(quick_sort($array));
?>