代码:
#include <iostream>
#include <vector>
#include <cstdbool>
using namespace std;
bool SwitchInt (int& a, int &b){
if (a == b) return true;
a += b;
b = a - b;
a -= b;
return true;
}
bool QuickSort (vector<int> &ivec, vector<int>::iterator small, vector<int>::iterator big){
if (small == big) return true;
vector<int>::iterator start = small;
vector<int>::iterator end = big;
vector<int>::iterator flag = small;
while (small != big){
if (*small > *flag){
SwitchInt(*small, *flag);
flag = small;
small++;
continue;
}
if (*big < *flag){
SwitchInt(*big, *flag);
flag = big;
big--;
continue;
}
}
QuickSort(ivec, start, small);
QuickSort(ivec, big, end);
return true;
}
int main (void){
vector<int> ivec;
int num = 0;
while (cin >> num){
ivec.push_back(num);}
QuickSort(ivec, ivec.begin(), ivec.end());
for (int num: ivec)
cout << num;
return 0;
}
运行时有指针超界的错误,但是我检查不出来