#include <iostream>
#include <set>
#include <string>
using namespace std;
struct node
{
int a,b;
node(int aa, int bb)
{a=(aa),b=(bb);}
};
struct cmp
{
bool operator()(node s1,node s2)
{
if( s1.a != s2.a )
return s1.a > s2.a;
return s1.b>s2.b;
}
};
set<node, cmp>words;
int main()
{
words.insert(node(1,1));
words.insert(node(2,1));
words.insert(node(3,2));
words.insert(node(4,3));
words.insert(node(5,3));
words.insert(node(5,-2));
set<node>::iterator mbegin;
set<node>::iterator mend = words.end();
for( mbegin = words.begin(); mbegin != mend; ++mbegin)
cout<<mbegin->a<<" "<<mbegin->b<<endl;
return 0;
}
自定义set比较函数
最新推荐文章于 2022-06-28 11:21:41 发布