ika #6646(2008/07/03 03:39 GMT) [ D ] Rating1/1=1.00
Counting sort
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
private import std.stdio; void main() { int[] a = [1, 9, 4, 8, 9, 6, 3, 9, 5, 2]; a.countingSort(1, 10); writeln(a); } void countingSort(int[] array, int min, int max) { auto counts = new uint[max - min + 1]; foreach(n; array) { counts[n - min]++; } auto p = array.ptr; foreach(i, c; counts) { p[0..c] = i + min; p += c; } }
Rating1/1=1.00-0+
1 reply [ reply ]
ika
#6646()
[
D
]
Rating1/1=1.00
Counting sort
Rating1/1=1.00-0+
1 reply [ reply ]