题目
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/6ffff8eaa55ff6781c787aabfa15fa2f.png)
N诺 1590. 快速排序
代码(7.19 首刷自解)
#include<iostream>
#include<vector>
#include<stdlib.h>
using namespace std;
void quickSort(vector<int>& nums, int l, int r) {
if(l >= r)
return;
int pivot = nums[rand()%(r-l+1)+l];
int left = l-1, right = r+1;
while(left < right) {
while(nums[++left] < pivot);
while(nums[--right] > pivot);
if(left < right)
swap(nums[left], nums[right]);
}
quickSort(nums, l, right);
quickSort(nums, right+1, r);
}
int main() {
int n;cin>>n;
vector<int> nums(n);
for(int i = 0; i < n; i++) {
int m;cin>>m;
nums[i] = m;
}
quickSort(nums, 0, n-1);
for(int i = 0; i < n; i++)
cout<<nums[i]<<" ";
return 0;
}