快速排序-java
static int[] quickSort(int[] array, int L, int R) { int i = L; int j = R; int pivot = array[(L + R) / 2]; while (i < j) { while (array[i] < pivot) { i++; } while (array[j] > pivot) { j--; } if (i <= j) { int temp = array[i]; array[i] = array[j]; array[j] = temp; i++; j--; } } if (j > L) { quickSort(array, L, j); } if (i < R) { quickSort(array, i, R); } System.out.println(Arrays.toString(array)); return array; }
浙公网安备 33010602011771号