Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
function counting_sort(&$arr, $min, $max)
|
||||
{
|
||||
$count = array();
|
||||
for($i = $min; $i <= $max; $i++)
|
||||
{
|
||||
$count[$i] = 0;
|
||||
}
|
||||
|
||||
foreach($arr as $number)
|
||||
{
|
||||
$count[$number]++;
|
||||
}
|
||||
$z = 0;
|
||||
for($i = $min; $i <= $max; $i++) {
|
||||
while( $count[$i]-- > 0 ) {
|
||||
$arr[$z++] = $i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
$ages = array();
|
||||
for($i=0; $i < 100; $i++) {
|
||||
array_push($ages, rand(0, 140));
|
||||
}
|
||||
counting_sort($ages, 0, 140);
|
||||
|
||||
for($i=0; $i < 100; $i++) {
|
||||
echo $ages[$i] . "\n";
|
||||
}
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue