//快排
void QuicklySort(vector<int>& nums, int start, int end, bool reverse =false) {
if (start + 1 >= end)
return;
int conindex = nums[start];
int left = start, right = end - 1;
while (left < right) {
if (!reverse) {
while (left < right && nums[right] >= conindex)
--right;
nums[left] = nums[right];
while (left < right && nums[left] <= conindex)
++left;
nums[right] = nums[left];
}
else {
while (left < right && nums[right] <= conindex)
--right;
nums[left] = nums[right];
while (left < right && nums[left] >= conindex)
++left;
nums[right] = nums[left];
}
}
nums[left] = conindex;
QuicklySort(nums, start, left, reverse);
QuicklySort(nums, left + 1, end, reverse);
}
c++之快排代码
最新推荐文章于 2024-05-14 10:51:55 发布