@Test public void testRadixSort() { int a = 1; int b = 87654321; int c = 2147483647; System.out.println("number: " + a + ", bit: " + SortUtil.getDigitBit(a)); System.out.println("number: " + b + ", bit: " + SortUtil.getDigitBit(b)); System.out.println("number: " + c + ", bit: " + SortUtil.getDigitBit(c)); System.out.println("number: " + c + ", 1 bit is: " + SortUtil.getFigure(c, 1) + ", 5 bit is: " + SortUtil.getFigure(c, 5) + ", 10 bit is: " + SortUtil.getFigure(c, 10)); int[] testArray = {10000, 4, 12, 0, 456, 789, 88, 66, 1224, 1204, 1412, 12345}; int maxBit = 1; for (int i = 0; i < testArray.length; i++) { int numberBit = SortUtil.getDigitBit(testArray[i]); if (numberBit > maxBit) { maxBit = numberBit; } } SortUtil.radixSort(testArray, maxBit); System.out.println("call radixSort, result is: "); for (int i = 0; i < testArray.length; i++) { System.out.println(testArray[i] + "\t"); } System.out.println(); }
public static void radixSort(int[] data, int maxBit) { final int digitTypeNum = 10; int[] bucket = new int[data.length]; int[] count = new int[digitTypeNum]; for (int k = 1; k <= maxBit; k++) { for (int i = 0; i < digitTypeNum; i++) { count[i] = 0; } for (int i = 0; i < data.length; i++) { count[getFigure(data[i], k)]++; } for (int i = 1; i < digitTypeNum; i++) { count[i] = count[i] + count[i - 1]; } for (int i = data.length - 1; i >= 0; i--) { int j = getFigure(data[i], k); bucket[count[j] - 1] = data[i]; count[j]--; } for (int i = 0; i < data.length; i++) { data[i] = bucket[i]; } } }
SortUtil { public static void radixSort(int[] data, int maxBit) { final int digitTypeNum = 10; int[] bucket = new int[data.length]; int[] count = new int[digitTypeNum]; for (int k = 1; k <= maxBit; k++) { for (int i = 0; i < digitTypeNum; i++) { count[i] = 0; } for (int i = 0; i < data.length; i++) { count[getFigure(data[i], k)]++; } for (int i = 1; i < digitTypeNum; i++) { count[i] = count[i] + count[i - 1]; } for (int i = data.length - 1; i >= 0; i--) { int j = getFigure(data[i], k); bucket[count[j] - 1] = data[i]; count[j]--; } for (int i = 0; i < data.length; i++) { data[i] = bucket[i]; } } } }
SortUtil { public static void radixSort(int[] data, int maxBit) { final int digitTypeNum = 10; int[] bucket = new int[data.length]; int[] count = new int[digitTypeNum]; for (int k = 1; k <= maxBit; k++) { for (int i = 0; i < digitTypeNum; i++) { count[i] = 0; } for (int i = 0; i < data.length; i++) { count[getFigure(data[i], k)]++; } for (int i = 1; i < digitTypeNum; i++) { count[i] = count[i] + count[i - 1]; } for (int i = data.length - 1; i >= 0; i--) { int j = getFigure(data[i], k); bucket[count[j] - 1] = data[i]; count[j]--; } for (int i = 0; i < data.length; i++) { data[i] = bucket[i]; } } }  }
SortUtil { public static void radixSort(int[] data, int maxBit) { final int digitTypeNum = 10; int[] bucket = new int[data.length]; int[] count = new int[digitTypeNum]; for (int k = 1; k <= maxBit; k++) { for (int i = 0; i < digitTypeNum; i++) { count[i] = 0; } for (int i = 0; i < data.length; i++) { count[getFigure(data[i], k)]++; } for (int i = 1; i < digitTypeNum; i++) { count[i] = count[i] + count[i - 1]; } for (int i = data.length - 1; i >= 0; i--) { int j = getFigure(data[i], k); bucket[count[j] - 1] = data[i]; count[j]--; } for (int i = 0; i < data.length; i++) { data[i] = bucket[i]; } } }  static void setIsPrint(boolean isPrint); static int[] initArray(final int n); static void print(int[] data); static void selectSort(int[] data); static void insertSort(int[] data); static void binaryInsertionSort(int[] data); static void shellSort(int[] data); static void bubbleSort(int[] data); static void quickSort(int[] data); static void mergeSort(int[] data); static void heapSort(int[] data); static void radixSort(int[] data, int maxBit); static int getDigitBit(int data); static int getFigure(int data, int n); List<SortObject<Double>> multiSort(int num, boolean ascend); }
SortUtil { public static void radixSort(int[] data, int maxBit) { final int digitTypeNum = 10; int[] bucket = new int[data.length]; int[] count = new int[digitTypeNum]; for (int k = 1; k <= maxBit; k++) { for (int i = 0; i < digitTypeNum; i++) { count[i] = 0; } for (int i = 0; i < data.length; i++) { count[getFigure(data[i], k)]++; } for (int i = 1; i < digitTypeNum; i++) { count[i] = count[i] + count[i - 1]; } for (int i = data.length - 1; i >= 0; i--) { int j = getFigure(data[i], k); bucket[count[j] - 1] = data[i]; count[j]--; } for (int i = 0; i < data.length; i++) { data[i] = bucket[i]; } } }  static void setIsPrint(boolean isPrint); static int[] initArray(final int n); static void print(int[] data); static void selectSort(int[] data); static void insertSort(int[] data); static void binaryInsertionSort(int[] data); static void shellSort(int[] data); static void bubbleSort(int[] data); static void quickSort(int[] data); static void mergeSort(int[] data); static void heapSort(int[] data); static void radixSort(int[] data, int maxBit); static int getDigitBit(int data); static int getFigure(int data, int n); List<SortObject<Double>> multiSort(int num, boolean ascend);  }