返回列表 發帖
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. vector<int> v= {5,7,3,9,8,1,2};
  4. int len;
  5. bool compare(int a, int b)
  6. {
  7.     return a>b;
  8. }
  9. void show()
  10. {
  11.     for(int i: v)
  12.         cout<<i<<" ";
  13.     cout<<endl;
  14. }
  15. void show2()
  16. {
  17.     for(int i=0; i<len; i++)
  18.         cout<<v[i]<<" ";
  19.     cout<<endl;
  20. }
  21. void show3()
  22. {
  23.     for(auto it=begin(v); it!=end(v); it++)
  24.         cout<<*it<<" ";
  25.     cout<<endl;
  26. }
  27. int main()
  28. {
  29.     show();
  30.     len=v.size();
  31.     sort(begin(v), end(v));
  32.     show3();
  33.     sort(begin(v), end(v), compare);
  34.     show();
  35.     return 0;
  36. }
複製代碼

TOP

返回列表