Sorting algorithms/Counting sort: Difference between revisions

added langur language example
(→‎{{header|C}}: I changed the function called counting_sort() which actually finds the minimum and maximum elements in the array and does nothing with them.)
(added langur language example)
Line 1,263:
Sorted : [-31, 0, 1, 2, 2, 4, 65, 83, 99, 782]
</pre>
 
=={{header|Langur}}==
<lang Langur>val .countingSort = f(.array, .min, .max) {
var .count = arr(.max-.min+1, 0)
for .i in .array {
.count[.i-.min+1] += 1
}
var .result = []
for .i of .count {
for 1 to .count[.i] {
.result ~= [.i+.min-1]
}
}
return .result
}
 
val .data = [7, 234, -234, 9, 43, 123, 14]
 
writeln "Original: ", .data
writeln "Sorted : ", .countingSort(.data, -250, 250)</lang>
 
{{out}}
<pre>Original: [7, 234, -234, 9, 43, 123, 14]
Sorted : [-234, 7, 9, 14, 43, 123, 234]</pre>
 
=={{header|Lua}}==
990

edits