Sorting algorithms/Counting sort: Difference between revisions

Added PowerShell
(→‎{{header|Julia}}: Corrected the ending <lang> tag)
(Added PowerShell)
Line 1,684:
end;
end count_sort;</lang>
 
=={{header|PowerShell}}==
<lang PowerShell>
function countingSort($array) {
$minmax = $array | Measure-Object -Minimum -Maximum
$min, $max = $minmax.Minimum, $minmax.Maximum
$count = @(0) * ($max - $min + 1)
foreach ($number in $array) {
$count[$number - $min] = $count[$number - $min] + 1
}
$z = 0
foreach ($i in $min..$max) {
while (0 -lt $count[$i - $min]) {
$array[$z] = $i
$z = $z+1
$count[$i - $min] = $count[$i - $min] - 1
}
}
$array
}
 
$array = foreach ($i in 1..50) {Get-Random -Minimum 0 -Maximum 26}
"$array"
"$(countingSort $array)"
</lang>
<b>Output:</b>
<pre>
13 18 8 6 3 7 22 20 10 7 18 10 25 13 9 21 8 19 24 24 18 6 23 23 24 7 15 25 24 25 11 23 19 5 4 8 9 7 1 19 10 24 13 1 9 0 9 10 19 16
0 1 1 3 4 5 6 6 7 7 7 7 8 8 8 9 9 9 9 10 10 10 10 11 13 13 13 15 16 18 18 18 19 19 19 19 20 21 22 23 23 23 24 24 24 24 24 25 25 25
</pre>
 
=={{header|PureBasic}}==
678

edits