@Test public void testSelectSort() throws Exception { int[] origin = SortUtil.initArray(arraySize); SortUtil.print(origin); long start = System.currentTimeMillis(); SortUtil.selectSort(origin); long interval = System.currentTimeMillis() - start; System.out.println("call selectSort, time cost is: " + interval + "ms"); SortUtil.print(origin); }
public static void selectSort(int[] data) { if (data == null || data.length < 2) { return; } for (int p = 0; p < data.length - 1; p++) { int minIndex = p; for (int i = p + 1; i < data.length; i++) { if (data[i] < data[minIndex]) { minIndex = i; } } if (minIndex != p) { swap(data, p, minIndex); } } }
SortUtil { public static void selectSort(int[] data) { if (data == null || data.length < 2) { return; } for (int p = 0; p < data.length - 1; p++) { int minIndex = p; for (int i = p + 1; i < data.length; i++) { if (data[i] < data[minIndex]) { minIndex = i; } } if (minIndex != p) { swap(data, p, minIndex); } } } }
SortUtil { public static void selectSort(int[] data) { if (data == null || data.length < 2) { return; } for (int p = 0; p < data.length - 1; p++) { int minIndex = p; for (int i = p + 1; i < data.length; i++) { if (data[i] < data[minIndex]) { minIndex = i; } } if (minIndex != p) { swap(data, p, minIndex); } } }  }
SortUtil { public static void selectSort(int[] data) { if (data == null || data.length < 2) { return; } for (int p = 0; p < data.length - 1; p++) { int minIndex = p; for (int i = p + 1; i < data.length; i++) { if (data[i] < data[minIndex]) { minIndex = i; } } if (minIndex != p) { swap(data, p, minIndex); } } }  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 selectSort(int[] data) { if (data == null || data.length < 2) { return; } for (int p = 0; p < data.length - 1; p++) { int minIndex = p; for (int i = p + 1; i < data.length; i++) { if (data[i] < data[minIndex]) { minIndex = i; } } if (minIndex != p) { swap(data, p, minIndex); } } }  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);  }