Counting Sort
计数排序算法
基本属性
public static void main(String[] args) {
int[] array = new int[]{5, 7, 1, 8, 9, 2, 3, 4, 1, 3, 6, 2, 4, 0};
int[] count = new int[9 - 0 + 1];
// counting sort
for (int i = 0; i < array.length; i++) {
count[array[i]] = count[array[i]] + 1;
}
// iterate counting
for (int i=0;i<count.length;i++){
int temp = count[i];
for(int j=0;j<temp;j++){
System.out.print(i);
}
}
// result
// 01122334456789
}

Last updated