1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| void quick_sort_Book(vector<int>& nums,int left,int right) { if(left<=right) { int pivot=quick_sort_pivot(nums,left,right); quick_sort_Book(nums,left,pivot-1); quick_sort_Book(nums,pivot+1,right); } } int quick_sort_pivot(vector<int>& nums,int left,int right) { int mid=nums[right]; int begin=left,end=right-1; while(begin<end) { while(nums[begin]<mid&&begin<end) begin++; while(nums[end]>=mid&& begin<end) end--; swap(nums[begin],nums[end]); } if(nums[begin]>=nums[right]) { swap(nums[begin],nums[right]); } else begin++; return begin; }
|