C++ std::multiset
std::multiset
template < class T, // multiset::key_type/value_type
class Compare = less<T>, // multiset::key_compare/value_compare
class Alloc = allocator<T> > // multiset::allocator_type
> class multiset;
Multiple-key set
Multisets are containers that store elements following a specific order, and where multiple elements can have equivalent values.
In a multiset, the value of an element also identifies it (the value is itself the key, of type T). The value of the elements in a multiset cannot be modified once in the container (the elements are always const), but they can be inserted or removed from the container.
Internally, the elements in a multiset are always sorted following a specific strict weak ordering criterion indicated by its internal comparison object (of type Compare).
multiset containers are generally slower than unordered_multiset containers to access individual elements by their key, but they allow the direct iteration on subsets based on their order.
Multisets are typically implemented as binary search trees.
Container properties
- Associative Elements in associative containers are referenced by their key and not by their absolute position in the container.
- Ordered The elements in the container follow a strict order at all times. All inserted elements are given a position in this order.
- Set The value of an element is also the key used to identify it.
- Multiple equivalent keys Multiple elements in the container can have equivalent keys.
- Allocator-aware The container uses an allocator object to dynamically handle its storage needs.
** Other Function please see the std::set container **
Code Example
#include <iostream>
#include <set>
using namespace std;
bool fncomp(int lhs, int rhs)
{ return lhs < rhs; }
struct classcomp
{
bool operator() (const int& lhs, const int& rhs) const
{ return lhs<rhs; }
};
int main(int argc, char **argv)
{
multiset<int> first;
int myints[] = {10,20,30,20,20};
multiset<int> first1(myints, myints+5);
multiset<int> first2(first1);
multiset<int> first3(first2.begin(),first2.end());
multiset<int, classcomp> first4;
bool (*fn_pt)(int,int) = fncomp;
multiset<int, bool(*)(int,int)> first5(fn_pt);
/** other function please to reference other container */
return 0;
}
Reference
C++ std::multiset的更多相关文章
- std::multiset
Set.multiset都是集合类, 差别在与set中不允许有重复元素, multiset中允许有重复元素. sets和multiset内部以平衡二叉树实现. multiset 多重集合容器是一个 ...
- UVA11136Hoax or what( multiset的应用)
题目链接 题意:n天,每天往一个箱子里放m个数,放完之后取最大的Max和最小的min做差,并把这两个数去掉,求n天之后的和 multiset 和 set的原理是相似的,multiset可以存多个相同的 ...
- STL之multiset
参见http://www.cplusplus.com/reference/set/multiset/ template < class T, ...
- HDU 2275 multiset
题意:n个操作 Push 入容器 Pop弹出一个 满足<=该数的最大的数(若没有输出No Element!) 开始用set打了一遍wrong了,这里入容器的数是有重复的,所以用multiset ...
- SPOJ - VISIBLEBOX [multiset的使用]
tags:[STL][sort][贪心]题解:做法:先对数组a进行排序,再将数组a从头到尾扫一遍,使用multiset维护最小值,如果,即将放入集合的数字>=最小值的两倍,那我们就删除掉多重集合 ...
- 洛谷.1110.[ZJOI2007]报表统计(Multiset Heap)
题目链接 主要思路 /* 对于询问1,用堆代替multiset/Splay 对于询问2,multiset 1.注意哨兵元素 2.注意multiset中删除时是删除某元素的一个位置,而不是这个元素!这个 ...
- 洛谷.1110.[ZJOI2007]报表统计(Multiset)
题目链接 主要思路 /* 其实只需要multiset即可 对于询问1,删除.插入差值,输出最小元素 对于询问2,插入后用前驱后继更新 1.注意哨兵元素 2.注意multiset中删除时是删除某元素的一 ...
- UVA 11136 Hoax or what (multiset)
题目大意: 超时进行促销.把账单放入一个箱子里 每次拿取数额最大的和最小的,给出 最大-最小 的钱. 问n天总共要给出多少钱. 思路分析: multiset 上直接进行模拟 注意要使用long lo ...
- 记两个std接口equal_range,set_difference
1.equal_range equal_range是C++ STL中的一种二分查找的算法,试图在已排序的[first,last)中寻找value,它返回一对迭代器i和j,其中i是在不破坏次序的前提下, ...
随机推荐
- 配置Chrome Driver
书中使用Firefox driver出现莫名问题,大概是firefox的版本太新了,懒得降级处理,故学习配置Chome driver进行测试. 1.到http://chromedriver.stora ...
- mybatis框架中分页的实现
2.分页的实现? 分页的时候考虑的问题: 分页的大小,分页的索引. 比如:分页的大小为10,分页的起始索引为1(索引从1开始) 第一页:1到10. 起始行号: (页的索引-1)*分页大小+1 结 ...
- Unity 编辑器的 界面布局 保存方法
在软件界面的右上角(关闭按钮的下方),点击 layout (界面)的下拉箭头. 弹出选项中的 save layout....(保存界面选项),输入命名,就可以生成这个界面的布局. (软件本身也有 ...
- Java打jar包详细教学
如果我们需要将写好并测试OK的公共接口供多个项目使用,我们可以不用拷贝源代码,可以编译后打包成jar文件,这样会很方便许多,修改的话也方便,直接修改源代码打一个新jar包替换即可,下面是打包的详细教程 ...
- 倒计时(jQuery)
倒计时,在网页制作中会经常用到,特别是一些节日活动页面运用更是广泛.今天就和大家分享一下jQuery如何实现倒计时.话不多说,言归正传,倒计时开始: 首先,既然是用jQuery实现,那么前提就是要先引 ...
- java线程小结3
1. 多线程概述 要实现多线程可以通过继承Thread和实现Runnable接口.不过这两者之间存在一些区别.其中最重要的区别就是,如果一个类继承Thread类,则不适合于多个线程共享资源,而实现了R ...
- Java猜拳小游戏(剪刀、石头、布)
1.第一种实现方法,调用Random数据包,直接根据“1.2.3”输出“剪刀.石头.布”.主要用了9条输出判断语句. import java.util.Random; import java.util ...
- PowerPoint
工具/原料 PowerPoint 2007 百度经验:jingyan.baidu.com 一.PowerPoint2007基础知识 1 桌面快捷方式:也可以“开始”菜单→程序→Microsoft Of ...
- ListView之头部浮动效果
ListView 中有时需要在顶部固定一个浮动栏,当向上滑动 ListView 时,浮动栏固定在顶部,当向下滑动 ListView 到其 HeaderView 可见时,浮动栏成为ListView的一部 ...
- 数据库优化之锁表查询 (Sql Server)
查询锁表语句 select request_session_id spid,DB_NAME(resource_database_id) databaseName, OBJECT_NAME(resour ...