快速排序:PHP 快速排序
程序员文章站
2022-05-28 09:26:50
...
本文链接http://www.cxybl.com/html/wlbc/Php/20130319/37248.html
- //Quick Sort
- function quickSort(array $array){
- static $run = 0;
- $len = count($array);
- if($len return $array;
- $arrleft=array();
- $arrright=array();
- $flag = $array[0];
- for($i=1;$i$len;$i++){
- if($array[$i]$flag){
- $arrleft[]=$array[$i];
- }else{
- $arrright[] = $array[$i];
- }
- }
- $arrleft = quickSort($arrleft);
- $arrright = quickSort($arrright);
- $run++;
- return array_merge($arrleft,array($flag),$arrright);
- }
- $data= array(10,12,43,32,123,12);
- $newarr = quickSort($data);
- print_r($newarr);
- ?>