比較しないソートの作成
Posted feedbacks - PHP
バケツで。
see: バケットソート
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <?php
$min = -1;
$max = 10;
$input = array(-1, 9, 4, 8, 9, 6, 3, 9, 5, 2);
$sorted = bucketsort($min, $max, $input);
function bucketsort($min, $max, $input){
for($i = $min; $i <= $max; $i++)
$temp[$i] = 0;
foreach($input as $v)
$temp[$v]++;
foreach($temp as $k => $v)
for($i = 0; $i < $v; $i++)
$sorted[] = $k;
return $sorted;
}
|


sweetie089 #6628() Rating3/3=1.00
[ reply ]