$a=array(3=>4,'world'=>3,8,9,2);
function quick($arr){
if(count($arr)<=1)
return $arr;
foreach($arr as $key=>$val){
$a[]=$val;
break;
}
$left=array();
$right=array();
$num=0;
foreach($arr as $key=>$val){
if($num==0){
$num=1;
continue;
}
if($val<=$a[0]){
$left[$key]=$val;
}else{
$right[$key]=$val;
}
}
$left=quick($left);
$right=quick($right);
$arrFinal=array_merge($left,$a,$right);
return $arrFinal;
}
print_r(quick($a));
阅读(1025) | 评论(0) | 转发(0) |