快速排序
public class QuickSort {
public static int partition(int[] arr, int l, int r) {
int pivot = arr[l];
int left = l;
while (l < r) {
while (l < r && arr[r] >= pivot)
r--;
while (l < r && arr[l] <= pivot)
l++;
if (l < r) {
int t = arr[l];
arr[l] = arr[r];
arr[r] = t;
}
}
arr[left] = arr[l];
arr[l] = pivot;
return l;
}
public static void quick(int[] arr, int l, int r) {
if (l < r) {
int pos = partition(arr, l, r);
quick(arr, l, pos - 1);
quick(arr, pos + 1, r);
}
}
}