快速排序 C++实现

 

void quickSort(vector<int>& nums, int start, int end){
        if(start >= end)    return;
        int left = start, right = end;
        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;
        quickSort(nums, start, left - 1);
        quickSort(nums, left + 1, end);
        return;
}        

 

posted @ 2021-01-12 12:50  zeroPatrick  阅读(52)  评论(0编辑  收藏  举报