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):是一种各元素之间有顺序关系的线性表,是一种线性结构的可序群集.顺序性容器中的每个元素均有固定的位 ...
随机推荐
- ESB的几个基本概念
京-星之泪: 请教一个问题:esb中路由和管道对的概念应该怎么理解,各自有什么用途,他们之间的关系 北京-kimmking: transport endpoint inbound outboun ...
- ARM JTAG 20
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0499b/BEHEIHCE.html he ARM JTAG 20 co ...
- 解决Arcgis10.2.2中dbf文件用EXCEL打开乱码问题
1.开始 -- 运行,输入”Regedit“,打开 注册表 . 2.如是用的是 10.x 版本 ArcGIS Desktop,定位到 ‘计算机\HKEY_CURRENT_USER\Software\E ...
- Windows 7 下玩游戏不能全屏
问题描述:许多用户反映,在 Windows 7 环境下,全屏游戏时两边屏幕都是黑的,只好窗口运行了.其实这是正常现象:有些游戏本身并没有提供宽屏分辨率支持.其图形界面都是按照一定比例(如 4:3)来设 ...
- SQL 条件 判断 select case as
" then "返回的数据1" " then "返回的数据2" else "返回的其他数据" end as 新的列名 f ...
- springboot2.X集成HttpClient 发送HTTPS 请求
1)jar <!--httpclient 发送外部https/http 请求--> <dependency> <groupId>org.apache.httpcom ...
- Selenium2+python自动化58-读取Excel数据(xlrd)
前言 当登录的账号有多个的时候,我们一般用excel存放测试数据,本节课介绍,python读取excel方法,并保存为字典格式. 一.环境准备 1.先安装xlrd模块,打开cmd,输入pip inst ...
- nyis oj 68 三点顺序 (计算几何基础)
三点顺序 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描写叙述 如今给你不共线的三个点A,B,C的坐标,它们一定能组成一个三角形,如今让你推断A,B,C是顺时针给出的还是逆 ...
- hue解决timed out(code THRIFTSOCKET):None
报错栈: Traceback (most recent call last): File , in decorator return func(*args, **kwargs) File , in e ...
- java单个方法达到了65536字节的限制
可以使方法更小的一件事是关闭调试.打开调试时,每一行(带代码)都有一个标记该行的语句. 不.重构代码.没有方法应该那么久.永远. Write small methods! 说真的:任何IDE都会指导您 ...