排序算法reverse反转

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

class Print
{
public:
   void operator()(int i)
   {
      cout << i << endl;
   }
};

int main()
{
   vector<int> v;
   for(int i = 0; i < 10; i++)
   {
      v.push_back(i);
   }

   for_each(v.begin(), v.end(), Print());

   cout << "--------" << endl;

   reverse(v.begin(), v.end());
   for_each(v.begin(), v.end(), Print());
   
   return 0;
}
$ ./a.out       
0
1
2
3
4
5
6
7
8
9
--------
9
8
7
6
5
4
3
2
1
0
posted @ 2022-07-31 16:08  thomas_blog  阅读(24)  评论(0编辑  收藏  举报