Java快速排序

时间:2022-04-16 20:18:24

快速排序:

 public int Partition(int[] nums, int low, int high) {
int pivot = nums[low]; while (low < high) {
while (nums[high] >= pivot && low < high)
high--;
nums[low] = nums[high];
while (nums[low] < pivot && low < high)
low++;
nums[high] = nums[low];
}
nums[low] = pivot;
return low;
} public void QuickSort(int[] nums, int left, int right) {
if (nums == null || nums.length < 0)
return;
if (left < right) {
int i = Partition(nums, left, right);
QuickSort(nums, left, i - 1);
QuickSort(nums, i + 1, right);
}
}