经测试代码如下:
/**
* 关联数组快速排序
*
* @param
* @arrange (512.笔记) jb51.cc
**/
function qsort($a,$f) {
qsort_do(&$a,Count($a)-1,$f);
}
function qsort_do($a,$l,$r,$f) {
if ($l < $r) {
qsort_partition(&$a,&$lp,&$rp,$f);
qsort_do(&$a,$lp,$rp,$f);
}
}
function qsort_partition($a,$f) {
$i = $l+1;
$j = $l+1;
while ($j <= $r) {
if ($f($a[$j],$a[$l])) {
$tmp = $a[$j];
$a[$j] = $a[$i];
$a[$i] = $tmp;
$i++;
}
$j++;
}
$x = $a[$l];
$a[$l] = $a[$i-1];
$a[$i-1] = $x;
$lp = $i - 2;
$rp = $i;
}
/*** 代码来自编程之家 jb51.cc(jb51.cc) ***/
原文链接:https://www.f2er.com/php/528863.html