马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
自学视频:https://www.bilibili.com/video/a ... 3015703200680132216
参考代码:https://blog.csdn.net/helloworld_ptt/article/details/86170077
(刚开始学,还是小白,希望大家互相交流共同进步!)#include<iostream>
#include<vector>
using namespace std;
class Solution{
public:
void sorted(vector<int>* nums, int left, int right)
{
int i = left;
int j = right;
int pivot = (*nums)[i];
if(i < j)
{
while(i < j)//i == j stop
{
while(i < j && (*nums)[j] >= pivot) j--;
if(i < j)
{
(*nums)[i] = (*nums)[j];
i++;
}
while(i < j && (*nums)[i] <= pivot) i++;
if(i < j)
{
(*nums)[j] = (*nums)[i];
j--;
}
}
(*nums)[i] = pivot;
sorted(nums, left, i - 1);
sorted(nums, i + 1, right);
}
}
};
int main(void)
{
int num;
cout << "send number" << endl;
vector<int> list;
while(cin >> num)
{
list.push_back(num);
}
Solution test;
test.sorted(&list, 0, list.size()-1);
vector<int>::iterator it;
for(it = list.begin(); it != list.end(); it++)
{
cout << *it <<" ";
}
return 0;
}
|