标签:
function quick_sort(&$arr){ _quick_sort($arr, 0, count($arr) -1); } function _quick_sort(&$arr, $start, $end){ if($start >= $end){ return; } $m = partition($arr, $start, $end); echo $m; _quick_sort($arr, $start, $m - 1); _quick_sort($arr, $m + 1, $end); } function partition(&$arr, $start, $end){ $tmp = $arr[$start]; while($start < $end){ while ($start < $end && ($tmp <= $arr[$end])) { $end--; } swap($arr, $start, $end); while ($start < $end && ($arr[$start] <= $tmp) ) { $start++; } swap($arr, $start, $end); } return $start; } quick_sort($arr);
标签:
原文地址:http://www.cnblogs.com/fengfengtk/p/5452942.html