首页 > 其他 > 详细

Set <STL>

时间:2016-03-06 17:11:00      阅读:130      评论:0      收藏:0      [点我收藏+]

set是维护集合的容器

 

 1 #include <cstdio>
 2 #include <set>
 3 using namespace std;
 4 
 5 int main()
 6 {
 7     //声明
 8     set<int> s;
 9 
10     //插入元素
11     s.insert(1);
12     s.insert(2);
13     s.insert(5);
14 
15     //查找元素
16     set<int>::iterator ite;
17     ite=s.find(1);
18     if(ite==s.end())   put("not found");
19     else puts("found");   
20 
21     ite=s.find(2);
22     if(ite==s.end())  puts("not found");
23     else puts("found");
24 
25     //删除元素
26     s.erase(3);
27 
28     //其他查找元素的方法
29     if(s.count(3)!=0)  puts("found");
30     else puts("not found");
31 
32     //遍历所有元素
33     for(ite=s.begin();ite!=s.end();++ite){
34         printf("%d\n",*ite);
35     }
36 }

 

Set <STL>

原文:http://www.cnblogs.com/wangmengmeng/p/5247749.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!