package mairuis.algorithm.sort;/**
* 计数排序
*
* @author Mairuis
* @date 2019/5/25
*/publicclassCountingSortextendsSort{publicstaticint[]countingSort(int[] a){int[] c =newint[a.length];//用无限循环模拟goto,实现超容就扩充数组然后从头开始for(;;){for(int anA : a){if(c.length <= anA){
c =newint[c.length <<2];break;}
c[anA]+=1;}break;}for(int i =1; i < c.length; i +=1){
c[i]+= c[i -1];}int[] b =newint[a.length];for(int anA : a){
b[c[anA]-1]= anA;
c[anA]-=1;}return b;}publicstaticint[]sort(int[] data){returncountingSort(data);}publicstaticvoidmain(String[] args){int[] data =generalIntegers(10);printArray(data);for(int i :sort(data)){
System.out.println(i);}}}