Set

 1 #include<cstdio>
 2 #include<iostream>
 3 #include<set>
 4 
 5 using namespace std;
 6 
 7 int main()
 8 {
 9     set<int>s;
10     s.insert(19);
11     s.insert(20);
12     s.insert(22);
13     s.insert(25);
14     set<int>::iterator ptr;
15     for(ptr=s.begin();ptr!=s.end();++ptr)
16     {
17         cout<<*ptr<<endl;
18     }
19     ptr=s.lower_bound(19);                      //返回指向大于(或等于)某值的第一个元素的迭代器
20     cout<<*ptr<<endl;
21     ptr=s.upper_bound(19);                      //返回大于某个值元素的迭代器
22     cout<<*ptr<<endl;
23     cout<<s.count(20)<<endl;
24     pair<set<int>::iterator,set<int>::iterator> p;
25     p=s.equal_range(22);                        //返回集合中与给定值相等的上下限的两个迭代器
26     cout<<*p.first<<endl;
27     cout<<*p.second<<endl;
28     set<int>S1;
29     S1.swap(s);
30     for(ptr=S1.begin();ptr!=S1.end();++ptr)
31     {
32         cout<<*ptr<<endl;
33     }
34     cout<<s.size();
35     s.clear();
36     S1.clear();
37     return 0;
38 }

 

posted on 2013-07-12 15:54  张狂不年轻°  阅读(136)  评论(0编辑  收藏  举报