快速排序

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
public static void quickSort(int[] arr, int start, int end) {
int l = start;
int h = end;
if (l >= h) return;
int pivot = arr[start];
while (l < h) {
while (l < h && pivot < arr[h]) h--;
if (l < h) arr[l] = arr[h];
while (l < h && pivot > arr[l]) l++;
if (l < h) arr[h] = arr[l];
}
arr[h] = pivot;
quickSort(arr, start, h - 1);
quickSort(arr, h + 1, end);
}