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