快排实现
public class Quick {
public static void main(String[] args) {
int[] arr = { 1, 3, 2, 6, 5, 8 };
sort(arr, 0, arr.length - 1);
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i]);
}
}
private static void sort(int[] arr, int i, int j) {
if (j <= i)
return;
int lo = i;
int mid = lo + 1;
int hi = j;
int tmp = arr[i];
while (mid <= hi) {
if (arr[mid] < tmp) {
int tmp1 = arr[mid];
arr[mid] = arr[lo];
arr[lo] = tmp1;
lo++;
mid++;
} else if (arr[mid] > tmp) {
int tmp1 = arr[mid];
arr[mid] = arr[hi];
arr[hi] = tmp1;
hi--;
}else{
mid++;}
}
sort(arr, i, lo - 1);
sort(arr, hi + 1, j);
}
}