#include #include #include
using namespace std;
void output(int &s) //输出函数 { cout<<s<<endl;
}
bool mycomp(const int &s1,const int &s2) { return s1>s2; }
int main(int argc,char * argv[]) { vector myvt;
myvt.insert(myvt.begin(),2); myvt.insert(myvt.begin()+1,4); myvt.insert(myvt.end(),1); cout<<"原顺序 :"< for_each(myvt.begin(),myvt.end(),output);
cout<<"升序:"< sort(myvt.begin(),myvt.end()); //默认升序排列 for_each(myvt.begin(),myvt.end(),output);
cout<<"降序:"< sort(myvt.begin(),myvt.end(),mycomp); for_each(myvt.begin(),myvt.end(),output); }