#include <iostream>
#include <vector>
using namespace std;
//一次for循环查找子数组最大值,将最大值记录在max,如果<0,则将sum=0,重新开始记录
int partition(vector<int> &nums,int left,int right)
{
int prior=nums[right];
int small=left;
for (int i=left; i<right; ++i) {
if (nums[i]<prior) {
if (i!=small) {
swap(nums[i], nums[small]);
}
small++;
}
}
swap(nums[right], nums[small]);
return small;
}
void quickSort(vector<int> &nums,int left,int right)
{
int n=nums.size();
int k=partition(nums,left,right);
if (k>left) {
quickSort(nums,left,k-1);
}
if (k<right) {
quickSort(nums,k+1,right);
}
}
int main()
{
vector<int> nums={1,-2,3,10,-4,7,2,-5};
int n=nums.size();
quickSort(nums,0,n-1);
for(int x:nums)
cout<<x<<" ";
return 0;
}