php关联数组快速排序的方法
本文实例讲述了php关联数组快速排序的方法。分享给大家供大家参考。具体如下:
<?php function qsort($a,$f) { qsort_do(&$a,0,Count($a)-1,$f); } function qsort_do($a,$l,$r,$f) { if ($l < $r) { qsort_partition(&$a,$l,$r,&$lp,&$rp,$f); qsort_do(&$a,$l,$lp,$f); qsort_do(&$a,$rp,$r,$f); } } function qsort_partition($a,$l,$r,$lp,$rp,$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; } ?>
希望本文所述对大家的php程序设计有所帮助。
相关推荐
blackeagleoht 2019-05-04
Masimaro 2020-06-21
Joymine 2020-06-06
清溪算法君老号 2020-06-01
GhostLWB 2020-04-20
田有朋 2020-04-19
sunjunior 2020-04-10
cmsmdn 2020-03-03
shenwenjie 2020-02-26
sunjunior 2020-02-15
hanyujianke 2020-01-13
路漫 2020-01-12
sunnyJam 2019-12-31
KilluaZoldyck 2019-12-15
yuanran0 2019-12-14
Happyunlimited 2019-12-10
baike 2019-12-09
yishujixiaoxiao 2019-12-02