void quick_sort(int nums[], int left, int right) {
if (left < right) {
int pivotpos = partition(nums, left, right);
quick_sort(nums, left, pivotpos - 1); //对左边部分递归
quick_sort(nums, pivotpos + 1, right);
}
}
int partition(int nums[], int left, int right) {
int pivot = nums[left];
while (left < right) { // 以枢轴为中界,划分左右
while (left < right && nums[right] >= pivot)
right --;
nums[left] = nums[right];
while (left < right && nums[left] <= pivot)
left ++;
nums[right] = nums[left];
}
nums[left] = pivot;
return left;
}
标签:sort,right,nums,int,代码,pivotpos,排序,快速,left
From: https://www.cnblogs.com/basilicata/p/16844648.html