自定义set比较函数

来源:互联网 发布:js urlencode转码 编辑:程序博客网 时间:2024/05/21 09:11
#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;}

0 0
原创粉丝点击