Rookie Engineer

If you aren't the kind of person that feels this way naturally, you'll need to become one in order to make it as a hacker. Otherwise you'll find your hacking energy is sapped by distractions like sex, money, and social approval.

  C++博客 :: 首页 :: 联系 :: 聚合  :: 管理
  24 Posts :: 0 Stories :: 2 Comments :: 0 Trackbacks

常用链接

留言簿

我参与的团队

搜索

  •  

最新评论

阅读排行榜

评论排行榜


Internally, the elements in a set are always sorted from lower to higher following a specific strict weak ordering criterion set on container construction.

 1#include <set>
 2#include <map>
 3
 4struct Node
 5{
 6    string s;
 7    char a;
 8    char b[9];
 9
10    bool operator <(const Node& node) const
11    {
12        // if(this->a == d.a)
13           // return this->s <d.s;
14        for(int i=0 ;i<sizeof(node.b);i++)
15        {
16            if(this->b[i] != node.b[i])
17                return this->b[i] < node.b[i];
18        }

19        return false;
20    }

21
22    Node()
23    {
24        memset(b,0,sizeof(b));
25    }
;
26}
;
27 set<Node> setV;
28 map<Node,int> mp;
29int _tmain(int argc, _TCHAR* argv[])
30{
31
32    Node a,b,c;
33    a.c[0= 'a';
34    a.a = "a111";
35    a.b = '1';
36    b.c[0= 'b';
37    b.a = "b222";
38    b.b = '2';
39    c.c[0= 'a';
40    c.a = "a333";
41    c.b = '3';
42
43    mp[a] = 1;
44    mp[b] = 2;
45    mp[c] = 3;
46    
47    setV.insert(a);
48    setV.insert(b);
49    setV.insert(c);
50
51    for(set<Node>::iterator iter = setV.begin();iter!= setV.end();++iter)
52    {
53        cout<<iter->b<<endl;
54    }

55
56   // for(map<Node,int>::iterator iter = mp.begin();iter!= mp.end();++iter)
57  //  {
58    //    cout<<iter->first.c<<" "<<iter->first.a<<" " <<iter->second<<endl;
59   // }
60
61    return 0;
62}


posted on 2011-11-01 13:45 micwu 阅读(324) 评论(0)  编辑 收藏 引用 所属分类: C++

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理