QuickSort(Java)

时间:2023-03-08 22:08:08
    private void quickSort(int[] input, int start, int end) {
if (start >= end) return; int index = partition(input, start, end); if (index > start) {
quickSort(input, start, index-1);
} if (index < end) {
quickSort(input, index+1, end);
}
} private int partition(int[] input, int start, int end) {
int index = start;
for (int i=start+1; i<=end; i++) {
if (input[i] < input[start]) {
index++;
if (index != i) {
swap(input, i, index);
}
}
}
swap(input, start, index); return index;
} private void swap(int[] input, int i, int j) {
int temp = input[i];
input[i] = input[j];
input[j] = temp;
}