- #include<bits/stdc++.h>
- using namespace std;
- vector<int> vec={5,7,3,9,8,1,2,4,6};
- int len=vec.size();
- bool compare(int a, int b)
- {
- return a>b;
- }
- void show(){
- cout<<"-----------------"<<endl;
- for(int i: vec)
- cout<<i<<" ";
- cout<<endl;
- }
- void show2()
- {
- for(int i=0; i<len; i++)
- cout<<vec[i]<<" ";
- cout<<endl;
- }
- void show3()
- {
- for(auto it=begin(vec); it!=end(vec); it++)
- cout<<*it<<" ";
- cout<<endl;
- }
- int main()
- {
- show();
- //sort(vec.begin(), vec.end());
- sort(begin(vec),end(vec));
- show2();
- //sort(vec.rbegin(), vec.rend());
- //sort(rbegin(vec), rend(vec));
- sort(begin(vec),end(vec),compare);
- show3();
- return 0;
- }
複製代碼 |