set指定排序规则

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

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

class Compare
{
public:
   bool operator()(int v1, int v2)
   {
      return v1 > v2;
   }
};

int main()
{
   set<int, Compare> s;
   s.insert(1);
   s.insert(3);
   s.insert(2);

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

   return 0;
}
$ ./a.out         
3
2
1
posted @ 2022-07-28 23:39  thomas_blog  阅读(44)  评论(0编辑  收藏  举报