STL - 容器 - MultiSet
MultiSet根据特定排序准则,自动将元素排序。
MultiSet允许元素重复。
一些常规操作:
MultiSetTest.cpp
#include <iostream>
#include <set>
#include <algorithm>
#include <iterator>
#include <functional>
#include "MultiSetTest.h" using namespace std; void MultiSetTest::operationDemo()
{
// type of the collection:
// - duplicates allowed
// - elements are integral values
// - descending order
multiset<int, greater<int>> coll1; // insert elements in random order using different member functions
coll1.insert({ , , , , , });
coll1.insert(); // print all elements
for (int elem : coll1) {
cout << elem << ' ';
}
cout << endl; // insert 4 again and process return value
auto ipos = coll1.insert();
cout << "4 inserted as element "
<< distance(coll1.begin(), ipos) + << endl; // assign elements to another multiset with ascending order
multiset<int> coll2(coll1.cbegin(), coll1.cend()); // print all elements of the copy using stream iterators
copy(coll2.cbegin(), coll2.cend(),
ostream_iterator<int>(cout, " "));
cout << endl; // remove all elements up to element with value 3
coll2.erase(coll2.begin(), coll2.find()); // remove all elements with value 5
int num;
num = coll2.erase();
cout << num << " element(s) removed" << endl; // print all elements
copy(coll2.cbegin(), coll2.cend(),
ostream_iterator<int>(cout, " "));
cout << endl;
} void MultiSetTest::run()
{
printStart("operationDemo()");
operationDemo();
printEnd("operationDemo()");
}
运行结果:
---------------- operationDemo(): Run Start ----------------
6 5 5 4 3 2 1
4 inserted as element 5
1 2 3 4 4 5 5 6
2 element(s) removed
3 4 4 6
---------------- operationDemo(): Run End ----------------
STL - 容器 - MultiSet的更多相关文章
- C++STL之multiset多重集合容器
multiset多重集合容器 multiset与set一样, 也是使用红黑树来组织元素数据的, 唯一不同的是, multiset允许重复的元素键值插入, 而set则不允许. multiset也需要声明 ...
- c++ stl容器set成员函数介绍及set集合插入,遍历等用法举例
c++ stl集合set介绍 c++ stl集合(Set)是一种包含已排序对象的关联容器.set/multiset会根据待定的排序准则,自动将元素排序.两者不同在于前者不允许元素重复,而后者允许. 1 ...
- STL容器迭代器失效分析
连续内存序列容器(vector, string, deque) 对于连续内存序列STL容器,例如vector,string,deque,删除当前iterator会使得后面所有的iterator都失效, ...
- STL容器的适用情况
转自http://hsw625728.blog.163.com/blog/static/3957072820091116114655254/ ly; mso-default-props:yes; m ...
- STL容器与配接器
STL容器包括顺序容器.关联容器.无序关联容器 STL配接器包括容器配接器.函数配接器 顺序容器: vector 行为类似于数组,但可以根据要求 ...
- STL容器的本质
http://blog.sina.com.cn/s/blog_4d3a41f40100eof0.html 最近在学习unordered_map里面的散列函数和相等函数怎么写.学习过程中看到了一个好帖子 ...
- STL容器总结
一. 种类: 标准STL序列容器:vector.string.deque和list. 标准STL关联容器:set.multiset.map和multimap. 非标准序列容器slist和rope.sl ...
- 使用GDB调试STL容器
GDB中print方法并不能直接打印STL容器中保存的变量,想知道STL容器保存的变量,使用如下办法: 1. 创建文件~/.gdbinit: # # STL GDB evaluators/views/ ...
- C++ STL容器总结
1. STL 容器 1. 按种类划分 顺序容器( sequence containers):是一种各元素之间有顺序关系的线性表,是一种线性结构的可序群集.顺序性容器中的每个元素均有固定的位 ...
随机推荐
- SpringBoot静态资源目录
在web开发中,静态资源的访问是必不可少的,如:图片.js.css 等资源的访问. SpringBoot对静态资源访问提供了很好的支持,基本使用默认配置就能满足开发需求. 在传统的web项目中静态资源 ...
- 【洛谷】4317:花神的数论题【数位DP】
P4317 花神的数论题 题目背景 众所周知,花神多年来凭借无边的神力狂虐各大 OJ.OI.CF.TC …… 当然也包括 CH 啦. 题目描述 话说花神这天又来讲课了.课后照例有超级难的神题啦…… 我 ...
- SCP用法
scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file] [-l limit] [-o ssh_option] [-P port ...
- thrift 安装 make 失败 ar: .libs/ThriftTest_constants.o: No such file or directory
$wget http://mirrors.cnnic.cn/apache/thrift/0.9.1/thrift-0.9.1.tar.gz $tar zxvf thrift-0.9.1.tar.gz ...
- linux 内核大牛-谢宝友
http://blog.chinaunix.net/uid/25845340.html 谢宝友:毕业于四川省税务学校税收专业,现供职于中兴通讯操作系统团队,对操作系统内核有较强的兴趣.专职于操作系统内 ...
- 不用软件快速拥有几百个QQ群并都是管理员
不用软件快速拥有几百个QQ群并都是管理员!快速拥有有几十万精准数据库的方法 !和快速收集上亿邮箱的思维方法(附上5种赚钱方法).pdf_免费高速下载|百度云 网盘-分享无限制 http://pan.b ...
- ARCGIS将WGS84坐标投影到高斯平面
将WGS84坐标投影到平面,一般採用的是UTM(通用横轴莫卡托投影).该方式多用于美国地区,而我国多用北京54和西安80高斯克吕格投影坐标.假如我们想把影像採用高斯克吕格投影到在平面上,而ARCGIS ...
- C#编程(三)
原文链接:http://blog.csdn.net/shanyongxu/article/details/46398713 C#中的常量 定义常量所需要的关键字:const,语法结果:const 变量 ...
- Android实例剖析笔记(三)
摘要:点介绍Activity的生命周期,通过一个简单的实验来摸索状态转换的机制 Activity的生命周期 Activity类中有许多onXXX形式的函数可以重载,比如onCreate,onStart ...
- umlの活动图
在介绍了曾经的类图和用例图等之后,因为对象图是描写叙述类图的某一个时刻的快照,所以类图没有详细的赋值可是对象图能够有详细的值.而包图是蕴含在画uml图之中的,对类图和对象图等进行分类的图,就像wind ...