1.冒泡排序
function sort($array) {
$length=count($array);
for ($i=$length; $i>0;$i--){
$swape=true;
for ($j=0;$j
if ($array[$j]>$array[$j 1]){
$temp }array[$j 1];
$array[$j 1]=$temp;
1
if ($swape)break;
}
return $array;
}
#2.氣泡排序
函數排序($input)
{
if(!isset($input))
# {
# return [];
}
do
{
# $sw ed = false;
# $sw $count = sizeof($input) - $i
{
if($input[$i 1]
名單($input[$i 1], $input[$i]) = [$input[$i], $input[$i 1]]; ## ##p true;
}
# }
}
while($swapped);
# 她排回輸入#}
$數組= [51158,1856,8459,67957,59748,58213,90876,39621,66570,64204,79935,27892,47615,4963,436 8, 42685,31577,5239,25385,56301,94083,23232,67025,44044,74813,34671,90235,65764,49709,12440216 144 ,13720,4204,77026,42348 ,19756,97222,78828,73437,48208,69858,19713,29411,49809,66174,52526277,7515,7873,8350,2829526277,7515,7873,8350,28299,6839,5796 7853 ,24932,93070,4696, 63015,9358,28302,3938,11754,33679,18492,91503,63395,12029,23954,27230,58336,16544,23606,613649,5396 92,76201 ,54616,59992,5676 ,97799,47910,98758,75043,72849,6466,68831,2246,69091,22296,6506,93729,86968,39583,46186,9674,57496,496 95,33963 ,77977,86805, 72686];
$array = sort($array);
echo implode(',', $array);
3.計數排序
函數排序($array, $min, $max)
{
$count = array();
for($i = $分鐘; $i
{
$count[$i] = 0;
名詞 }
foreach($array as $number)
{
$count[$number] ;
}
$z = 0;
# for($i = $min; $i
while( $count[$i]-- > 0 ) {
$array[$z ] = $i;
# # } } return $array;}4.插入排序function sort($array) { for ($i=1;$i5.快速排序function sort($input){ if(!isset($input))
{ return []; } $lt = []; $gt = []; if(sizeof($input) { return $input; }
## $key = key( $input);
$shift = array_shift($input);
foreach($input as $value)
{
# $value
}
### return array_merge(quickSort($lt), [$key => $shift], fastSort( $ gt));######}####$數組= 5,31577, 5239 04,7 7026,42348,19756,97222 ,78828 44,236 06,61349,37348, 78629,96145 ,39583,4618 6,96782,19074 ,46574,46704 ,99211,55295,33963,77977,86805,72686];
#$array = QuickSort($array);
#echo implode(#$array, $arrayort($array);
#echo implode(#$array, $arrayort($array);
#echo implode(#$array, $arrayort($array);
#echo implode(#$array, $arrayort($array);
6.選擇排序
function sort($array){
$length=count($array);
# for ($i=0 ;$i## $lowest=$i;
for ($j=$i 1;$j if ($array[$j] $lowest=$j; ## if ($i !==$lowest){
$temp=$array[$i];
$array[$i]## $array[$i]=$array[$low] ;
$array[$lowest]=$temp;
}
# }
return $
#array;
array; ————————————————版權聲明:本文為CSDN部落客「m0_37540251」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處連結及本聲明。以上是php演算法排序大全,面試必看演算法的詳細內容。更多資訊請關注PHP中文網其他相關文章!