public class QuickSort {
public static void quickSort(int[] arr, int front, int rear) {
if(front >= rear) {
return;
}
int i = front, povit = front, j = rear;
int tem = arr[povit];
while(i < j) {
while(i < j && arr[j] > tem) {
j--;
}
arr[povit] = arr[j];
povit = j;
while(i < j && arr[i] < tem) {
i++;
}
arr[povit] = arr[i];
povit = i;
}
arr[povit] = tem;
quickSort(arr, front, povit-1);
quickSort(arr, povit+1, rear);
}
public static void main(String[] args) {
int[] arr = {2, 13, 35, 12, 36, 4, 66, 93, 60};
System.out.println("before:" + Arrays.toString(arr));
quickSort(arr, 0, arr.length-1);
System.out.println("after:" + Arrays.toString(arr));
}
}
结果:
before:[2, 13, 35, 12, 36, 4, 66, 93, 60]
after:[2, 4, 12, 13, 35, 36, 60, 66, 93]