1 Packagesorting;2 3 /**4 * Base Sort5 * Average O (d (n+r)), preferably O (d (n+r)), Worst O (d (n+r)), Space complexity O (n+r), stable, more complex6 * d is the number of digits, R is the number of the list after distribution7 * @authorZeng8 *9 */Ten Public classJishupaixu { One A Public Static intGetnuminpos (intNumintPOS) { - intTMP = 1; - for(inti = 0; i < pos-1; i++) { theTMP *= 10; - } - return(num/tmp)% 10; - } + - Public Static intGetmaxweishu (int[] b) { + intmax = B[0]; A for(inti = 0; i < b.length; i++) { at if(B[i] >max) -Max =B[i]; - } - intTMP = 1, i = 1; - while(true) { -TMP *= 10; in if(Max/tmp! = 0) { -i++; to}Else + Break; - } the returni; * } $ Panax Notoginseng Public Static int[] Jishupaixu (int[] A,intd) { - the int[] Array =New int[10] [A.length + 1]; + for(inti = 0; I < 10; i++) { AArray[i][0] = 0;//Array[i][0] Record number of data in row I the } + for(intpos = 0; Pos < D; pos++) { -System.out.println ("Start Fenpei"); $ for(inti = 0; i < a.length; i++) {//Allocation Process $ intnum = Getnuminpos (a[i], POS + 1); - intindex = ++array[num][0]; -System.out.println ("a[" + i + "]-->" + "array[" + num + "] [" the+ index + "]"); -Array[num][index] =A[i];Wuyi } theSystem.out.println ("Start Shouji"); - for(inti = 0, j = 0; I < 10; i++) {//Collection Process Wu for(intK = 1; K <= Array[i][0]; k++) { -System.out.println ("a[" + j + "]=" + "array[" + i + "] [" About+ K + "]"); $A[j++] =Array[i][k]; - } -Array[i][0] = 0;//Reset, the next POS is also required to use - } A } + the returnA; - } $ the Public Static voidMain (string[] args) { the int[] B = {49, 38, 65, 197, 76, 213, 27, 50 }; the Jishupaixu (b, Getmaxweishu (b)); the for(inti:b) -System.out.print (i + "")); in the } the}
Sort algorithm Java implementation (cardinality sort)