publicclassCounting_sort{ staticint[] countingSort(int[] a) { int maxValue=0; for (int i : a) maxValue=i>maxValue?i:maxValue; int c[] = newint[maxValue + 1]; for (int i = 0; i < a.length; i++) c[a[i]]++;
int b[] = newint[a.length];
int count = 0; for (int i = 0; i <= maxValue; i++) { while (c[i] > 0) { b[count++] = i; c[i]--; } } return b; }