Sorting algorithms/Counting sort: Difference between revisions

Slate implementation
(add m4)
(Slate implementation)
Line 612:
ary.countingsort!.join(",")
# => "1,1,2,2,2,2,2,2,2,2,3,3,3,3,3,3,4,4,4,4,5,5,5,5,5,5,6,6,6,6,7,7,7,7,7,7,8,8,8,8,9,9,9,9,9,9,10,10,10,10"</lang>
 
=={{header|Slate}}==
 
<lang slate>
s@(Sequence traits) countingSortBetween: min and: max
[| counts index |
counts: ((0 to: max - min) project: [| :_ | 0]).
s do: [| :value | counts at: value - min infect: [| :count | count + 1]].
index: 0.
min to: max do: [| :value |
[(counts at: value - min) isPositive]
whileTrue:
[s at: index put: value.
index: index + 1.
counts at: value - min infect: [| :val | val - 1]]
].
s
].</lang>
 
=={{header|Smalltalk}}==