#include <iostream>
#include<vector>
using namespace std;
void quickSort(vector<int > & vec ,int start,int end) {
if (start < end) {
int left = start, right = end;
int priot = vec.at(start);
while (left <right)
{
while (left < right && vec.at(right) >= priot) right--;
if (left < right) vec.at(left++) = vec.at(right);
while (left < right && vec.at(left) <= priot) left++;
if (left < right) vec.at(right--) = vec.at(left);
}
vec.at(right) = priot;
quickSort(vec, start, left - 1);
quickSort(vec, left + 1, end);
}
}
int main() {
int a;
vector<int > vec;
cout << "请输入数字,进行快速排序:" << endl;
cout << "中间用空格 比如 :15 56 18 13 69Enter" << endl;
while (cin>>a)
{
vec.push_back(a);
if (cin.get() == ‘\n‘) break;
}
quickSort(vec, 0, vec.size() - 1);
cout <<endl<< "quick排序后" << endl;
for (auto & ele : vec) {
cout << ele << " ";
}
return 0;
}
原文:https://www.cnblogs.com/appearAndLeave/p/14839100.html