functionInsertsort ($arr){ $num=Count($arr); for($i= 1;$i<$num;$i++){ $key=$arr[$i]; for($j=$i-1;$j>= 0;$j--){ if($arr[$j] >$key){ $arr[$j+ 1] =$arr[$j]; $arr[$j] =$key; } } } return $arr;}functionBubblesort ($arr){ $num=Count($arr); for($i= 1;$i<$num;$i++ ){ for($j=$num-1;$j>=$i;$j-- ){ if($arr[$j] <$arr[$j-1] ){ $tmp _val=$arr[$j-1]; $arr[$j-1] =$arr[$j]; $arr[$j] =$tmp _val; } } } return $arr;}functionBucketsort ($arr){ $bucket=Array(); $idx= 0; foreach($arr as $value) { if(!Is_int($value))Continue; $bucket[$value] =$value; if($value>$idx)$idx=$value; } $rst=Array(); for($i= 0;$i<=$idx;$i++){ if(isset($bucket[$i])){ $rst[] =$bucket[$i]; } } return $rst;}functionExchangesort ($arr){ $num=Count($arr); for($i= 0;$i<$num-1;$i++){ for($j=$i+ 1;$j<$num;$j++){ if($arr[$i] >$arr[$j]){ $tmp=$arr[$i]; $arr[$i] =$arr[$j]; $arr[$j] =$tmp; } } } return $arr;}functionQuickSort ($arr){ $num=Count($arr); $l _num=$r _num= 0; $left=$right=Array(); for($i= 1;$i<$num;$i++){ if($arr[$i] >=$arr[0]){ $right[] =$arr[$i]; $r _num++; }Else{ $left[] =$arr[$i]; $l _num++; } } if($l _num> 1){ $left= QuickSort ($left); } $left[] =$arr[0]; if($r _num> 1){ $right= QuickSort ($right); } for($i= 0;$i<$r _num;$i++){ $left[] =$right[$i]; } return $left;}functionPigeonholesort ($arr){ $pigeonhole=Array(); foreach($arr as $value) { if(!Is_int($value))Continue; if(isset($pigeonhole[$value])) $pigeonhole[$value]++; Else $pigeonhole[$value] = 0; } $rst=Array(); $i= 0; while($pigeonhole[$i]){ for($j= 0;$j<$pigeonhole[$i];$j++){ $rst[] =$i; } $i++; } return $rst;}