class Solution {
public int[] quicklysort(int[] nums) {
quickSort(nums, 0, nums.length-1);
return nums;
}
public static void quickSort(int[] list, int low, int high){
if(low < high){
int middle = getMiddle(list, low, high);
quickSort(list, low, middle-1);
quickSort(list, middle+1, high);
}
}
public static int getMiddle(int[] list, int low, int high){
int temp = list[low];
while(low < high){
while(low < high && list[high] >= temp){ high--; }
list[low] = list[high];
while(low < high && list[low] <= temp){ low++; }
list[high] = list[low];
}
list[low] = temp;return low;
}
}
①先从队尾开始向前扫描且当low < high时,如果a[high] > tmp,则high–,但如果a[high] < tmp,则将high的值赋值给low,即arr[low] = a[high],同时要转换数组扫描的方式,即需要从队首开始向队尾进行扫描了
②同理,当从队首开始向队尾进行扫描时,如果a[low] < tmp,则low++,但如果a[low] > tmp了,则就需要将low位置的值赋值给high位置,即arr[low] = arr[high],同时将数组扫描方式换为由队尾向队首进行扫描.
③不断重复①和②,知道low>=high时(其实是low=high),low或high的位置就是该基准数据在数组中的正确索引位置.
https://blog.csdn.net/nrsc272420199/article/details/82587933