[size=medium][b]快速排序quickSort[/b][/size]
public class Test {
public static void main(String[] args) {
int arr[] = {3, 5, 6, 333, 5, 2, 1111, 1, 2, 3, 4, 5, 6, 7, 8, 8};
quickSort(arr, 0, arr.length - 1);
}
public static void quickSort(int arr[], int start, int end) {
if (start >= end) {return;}
int prviod = partion(arr, start, end);
quickSort(arr, start, prviod - 1);
quickSort(arr, prviod + 1, end);
}
public static int partion(int arr[], int start, int end) {
int j = start - 1;
int index = start;
for (; index < end; index++) {
if (arr[index] < arr[end]) {
swap(arr, j + 1, index);
j++;
}
}
swap(arr, j + 1, end);
System.out.println(Arrays.toString(arr));
return j + 1;
}
public static void swap(int arr[], int j, int index) {
int tmp = arr[j];
arr[j] = arr[index];
arr[index] = tmp;
}
}