multiset的插入与删除
2016-05-28 21:34
302 查看
<span style="font-size:14px;">#include <iostream> #include<functional> #include <set> #include<iterator> #include <algorithm> using namespace std; int main () { typedef multiset<int,greater<int> > IntSet; IntSet myset; int myints[] = {75,23,65,42,23}; for( int i = 0; i < 5; i++ ) { myset.insert( myints[i] ); } for( IntSet::const_iterator cite = myset.begin(); cite != myset.end(); ++cite ) { cout << *cite << ' '; // 75 65 42 23 23 } multiset< int, greater<int> >::iterator ite = find( myset.begin(), myset.end(), 23 ); if( ite != myset.end() ) { myset.erase(ite); //只删除一个,而 myset.erase(23); 会删除所有值为23的元素 } cout << endl; for( IntSet::const_iterator cite = myset.begin(); cite != myset.end(); ++cite ) { cout << *cite << ' '; // 75 65 42 23 } std::cout << '\n'; return 0; } </span>
相关文章推荐
- STL学习记录(八)Sets、Multisets
- 327. Count of Range Sum
- stl之multiset容器的应用
- 【深度探索STL】关联式容器set和multiset
- 【Baltic2007】【BZOJ1342】Sound静音问题
- multiset的使用
- 关联容器
- ZOJ 3612 Median multiset或vector+二分
- URAL 1880 Psych Up's Eigenvalues multiset水题
- 关于multiset中遇到的一个错误
- 【multiset】hdu 5349 MZL's simple problem
- STL学习——set/map/multiset/mulitmap篇
- STL学习——hash_set/hash_map/hash_multiset/hash_multimap篇
- HDU 4666 经典的求最远曼哈顿距离
- NYOJ--懒省事的小明
- Alice And Bob Hdu--复杂的贪心
- UVA 11136 Hoax or what 【multiset】
- hdu4666(multiset+优先级队列+堆)
- STL学习笔记-set/multiset容器(集合)
- STL之multiset简介