快速排序模板java
程序员文章站
2022-03-24 12:40:48
...
int next[];
public static void qkSort(int l, int h) {
int start = l;
int end = h;
int key = arr[start];
while (end > start) {
while (end > start && arr[end] > key) {
end--;
}
if (arr[end] <= key) {
int temp = arr[end];
arr[end] = arr[start];
arr[start] = temp;
}
while (end > start && arr[start] < key) {
start++;
}
if (arr[start] >= key) {
int temp = arr[start];
arr[start] = arr[end];
arr[end] = temp;
}
}
if (start > l) {
qkSort(l, start - 1);
}
if (end < h) {
qkSort(end + 1, h);
}
}