算法-12-快速排序-快排的最好最坏情况

class Solution {
public int[] sortArray(int[] nums) {
quickSort(nums, 0, nums.length - 1);
return nums;
}

public void quickSort(int[] nums, int l, int r) {
if(l >= r) return;
int i = l- 1, j = r + 1;
int key = nums[l];
while(i < j) {
while(nums[++i] < key);
while(nums[--j] > key);
if(i < j){
int tmp = nums[i];
nums[i] = nums[j];
nums[j] = tmp;
}
}
quickSort(nums, l, j);
quickSort(nums, j + 1, r);
}
}

 

posted on 2023-08-03 01:15  寻不到花的蝶  阅读(42)  评论(0编辑  收藏  举报