privatevoidquiteSort(int[] nums, int low, int high){ if (low >= high) { return; }
int left = low; int right = high; int index = (int) (Math.random() * (right - left) + left); int temp = nums[left]; nums[left] = nums[index]; nums[index] = temp; int standard = nums[left];
while (left < right) { while (left < right && nums[right] >= standard) { right--; } nums[left] = nums[right]; while (left < right && nums[left] <= standard) { left++; } nums[right] = nums[left]; } nums[left] = standard; if (left == nums.length - k) { return; } if (left > nums.length - k) { quiteSort(nums, low, left - 1); } quiteSort(nums, left + 1, high); } }