时间:2021-07-01 10:21:17 帮助过:26人阅读
function quicksort($seq) {
if (count($seq) > 1) {
$k = $seq[0];
$x = array();
$y = array();
for ($i=1; $i
if ($seq[$i] <= $k) {
$x[] = $seq[$i];
} else {
$y[] = $seq[$i];
}
}
$x = quicksort($x);
$y = quicksort($y);
return array_merge($x, array($k), $y);
} else {
return $seq;
}
}
$arr = array(12,2,16,30,8,28,4,10,20,6,18);
print_r(quicksort($arr));
?>
http://www.bkjia.com/PHPjc/478709.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/478709.htmlTechArticle?php function quicksort($seq) { if (count($seq) 1) { $k = $seq[0]; $x = array(); $y = array(); for ($i=1; $icount($seq); $i++) { if ($seq[$i] = $k) { $x[] = $seq[$i]; } else { $y[]...