快速排序:
public class QuickSort {
public static void main(String[] args) {
sort(new int[] { 5, 4, 2, 1, 9, 7, 10, 0, 3 }, 0, 8);
}
public static void sort(int arr[], int low, int high) {
int l = low;
int h = high;
int povit = arr[low];
while (l < h) {
while (l < h && arr[h] >= povit)
h--;
if (l < h) {
int temp = arr[h];
arr[h] = arr[l];
arr[l] = temp;
l++;
}
while (l < h && arr[l] <= povit)
l++;
if (l < h) {
int temp = arr[h];
arr[h] = arr[l];
arr[l] = temp;
h--;
}
}
System.out.print("l=" + (l + 1) + "h=" + (h + 1) + "povit=" + povit + "\n");
if (l > low)
sort(arr, low, h - 1);
if (h < high)
sort(arr, l + 1, high);
}
}