1 private void quickSort(int[] input, int start, int end) {
2 if (start >= end) return;
3
4 int index = partition(input, start, end);
5
6 if (index > start) {
7 quickSort(input, start, index-1);
8 }
9
10 if (index < end) {
11 quickSort(input, index+1, end);
12 }
13 }
14
15 private int partition(int[] input, int start, int end) {
16 int index = start;
17 for (int i=start+1; i<=end; i++) {
18 if (input[i] < input[start]) {
19 index++;
20 if (index != i) {
21 swap(input, i, index);
22 }
23 }
24 }
25 swap(input, start, index);
26
27 return index;
28 }
29
30 private void swap(int[] input, int i, int j) {
31 int temp = input[i];
32 input[i] = input[j];
33 input[j] = temp;
34 }
标签:index,end,int,quickSort,QuickSort,start,input,Java
来源: https://www.cnblogs.com/zhwcs/p/10388480.html