PHP 实现桶排序
<?php
function Bucket_sort($array){
//初始化桶大小
$min = min($array);
$max = max($array);
$book = array_fill($min, $max-$min+1, 0);
//将要进行的数据进行计数
foreach ($array as $key) {
$book[$key]++;
// echo $book[$key];
}
//返回数据
$resArr = array();
foreach ($book as $key => $value) {
for ($i=1; $i <= $value; $i++) {
$resArr[] = $key;
}
}
// print_r($resArr);
return $resArr;
}
$arr = array(8,100,50,22,15,6,1,1000,999,0);
$res = Bucket_sort($arr);
echo implode(',', $res);
?>