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

  33.     //sort(vec.rbegin(), vec.rend());
  34.     //sort(rbegin(vec), rend(vec));
  35.     sort(begin(vec),end(vec),compare);
  36.     show3();

  37.     return 0;
  38. }
複製代碼
hahahahahahahaha

TOP

返回列表