快速排序
#include<vector>
#include<iostream>
using std::vector;
using std::cin;
using std::cout;
void exchange(int& a, int& b) {
int tmp;
tmp = a;
a = b;
b = tmp;
}
int parition(vector<int>&vec,int begin,int end) {
int SM = begin - 1;
for (int j = begin; j < end; j++) {
if (vec[j] <= vec[end]) {
exchange(vec[SM + 1], vec[j]);
SM++;
}
}
exchange(vec[SM + 1], vec[end]);
return SM + 1;
}
void Sort(vector<int>&vec, int begin, int end) {
if (begin < end) {
int pos = parition(vec, begin, end);
Sort(vec, begin, pos - 1);
Sort(vec, pos + 1, end);
}
}
int main()
{
vector<int> vec;
int i;
while (cin >> i) {
vec.push_back(i);
}
int begin = 0;
int end = vec.size()-1;
Sort(vec, begin, end);
for (auto c : vec)
cout << c<<" ";
system("pause");