刚开始先cleara,之后再赋值,后来发现应该直接赋值的
//============================================================================
// Name : mergsort.cpp
// Author : qxyu
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
#include<vector>
using namespace std;
void merge(vector<int> &a, int p, int q, int r){
vector<int> res;
int i;
int j;
for(i = p, j = q+1; i <= q && j <=r;){
if(a[i]<=a[j])
{
res.push_back(a[i]);
i++;
}
else
{
res.push_back(a[j]);
j++;
}
}
if(j<=r){
while(j<=r){
res.push_back(a[j]);
j++;
}
}
else{
while(i<=q){
res.push_back(a[i]);
i++;
}
}
for(int i = p; i <= r; i ++)
a[i]=res[i-p];
}
void merge_sort(vector<int> &a, int p, int r){
if(p<r){
int q = (p+r)/2;
merge_sort(a, p,q);
merge_sort(a, q+1,r);
merge(a,p,q,r);
}
}
int main() {
vector<int> inp;
inp.push_back(90);
inp.push_back(0);
inp.push_back(10);
inp.push_back(11);
inp.push_back(9);
inp.push_back(90);
merge_sort(inp,0,6);
for(int i = 0; i <inp.size(); i ++)
cout << inp[i] << endl; // prints !!!Hello World!!!
return 0;
}