快速排序 #include <iostream> #include <vector> using namespace std;int partition(vector<int> &nums ,int left ,int right) {int pivot = nums[left];int i=left; int j=right;while (i<j){while (i<j && nums[j] >=pivot) j--;nums[i]=nums[j];while (i<j && nums[i] <=pivot) i++;nums[j]=nums[i];}nums[i]=pivot;return i ;}void quickSort(vector<int> &nums,int left,int right) {if(left < right){int pivotindex=partition(nums,left,right);quickSort(nums,left,pivotindex-1);quickSort(nums,pivotindex+1,right);} }int main() {vector<int>nums ={5,2,6,1,3,9,4,8,7};int right = nums.size()-1;int left = 0;quickSort(nums,left,right);for(auto &num : nums){std::cout<<num<<" ";}}