STL之<set>
2012-07-23 19:19
162 查看
Set用于存储不重复的元素,若重复存入同一元素,则set会将其覆盖掉。 #include <iostream> #include <set> using namespace std; set <int> h;//这个地方的int可以换为任意你想储存元素的类型 int main() { int n, x; cin >> n;
h.clear();//这条语句的目的是清理h; for(int i = 0; i < n; i++) { cin >> x; h.insert(x); } set <int>::iterator it; for(it = h.begin(); it != h.end(); it++) cout << (*it) << endl; if(h.find(3) != h.end()) cout << "Yes, 3 is in set h" << endl; else cout << "No, element does not exist" << endl; return 0; }
相关文章推荐
- 一种排序 set<stl> 无重复 + < 符号重载 ==
- STL:集合#include <set>
- <C++ STL set>集合并,交,差,对称差总结
- C++ Greedy Snake的OOP实现 贪食蛇 <list> STL初次学习
- &lt;Effective STL&gt;笔记--仿函数
- 发现Set<String> set = hashMap.keySet()的奥秘
- STL容器中的vector<摘自别人博客>
- 日期格式化标签<fmt:formatDate>&<fmt:setTimeZone>时区标签的使用demo
- .net集合类的研究--哈希表(二)--HashSet<T>
- NSUnknownKeyException', reason: '[<UIApplication 0x8a58320> setValue:forUndefinedKey:]
- <set>有感
- ArrayList、List<T>、HashSet<T>、LinkedList<T>各自优点和缺点,Dictionary<K,V>的内部存储数据方式有什么特殊的?
- STL中map的key能否用char *呢?当然可以! map<char *, char *>
- STL中sort<稍后自己会整理下的,感觉给的不全>
- Java集合转换【List<-->数组、List<-->Set、数组<-->Set、Map-->Set、Map-->List】
- JSP标签的<jsp:useBean>和<jsp:setProperty><jsp:getProperty>的使用
- STL的vector<string>的初始化方式总结
- <stl>将bytes上调至8的倍数
- ZOJ Problem Set - 3860Find the Spy (STL-> map 建立简单查询表 )
- &lt;Effective STL&gt;笔记--算法