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

cplusplus

C++ std::multiset的更多相关文章

  1. std::multiset

    Set.multiset都是集合类, 差别在与set中不允许有重复元素, multiset中允许有重复元素. sets和multiset内部以平衡二叉树实现.   multiset 多重集合容器是一个 ...

  2. UVA11136Hoax or what( multiset的应用)

    题目链接 题意:n天,每天往一个箱子里放m个数,放完之后取最大的Max和最小的min做差,并把这两个数去掉,求n天之后的和 multiset 和 set的原理是相似的,multiset可以存多个相同的 ...

  3. STL之multiset

    参见http://www.cplusplus.com/reference/set/multiset/ template < class T,                            ...

  4. HDU 2275 multiset

    题意:n个操作 Push 入容器 Pop弹出一个 满足<=该数的最大的数(若没有输出No Element!) 开始用set打了一遍wrong了,这里入容器的数是有重复的,所以用multiset ...

  5. SPOJ - VISIBLEBOX [multiset的使用]

    tags:[STL][sort][贪心]题解:做法:先对数组a进行排序,再将数组a从头到尾扫一遍,使用multiset维护最小值,如果,即将放入集合的数字>=最小值的两倍,那我们就删除掉多重集合 ...

  6. 洛谷.1110.[ZJOI2007]报表统计(Multiset Heap)

    题目链接 主要思路 /* 对于询问1,用堆代替multiset/Splay 对于询问2,multiset 1.注意哨兵元素 2.注意multiset中删除时是删除某元素的一个位置,而不是这个元素!这个 ...

  7. 洛谷.1110.[ZJOI2007]报表统计(Multiset)

    题目链接 主要思路 /* 其实只需要multiset即可 对于询问1,删除.插入差值,输出最小元素 对于询问2,插入后用前驱后继更新 1.注意哨兵元素 2.注意multiset中删除时是删除某元素的一 ...

  8. UVA 11136 Hoax or what (multiset)

    题目大意: 超时进行促销.把账单放入一个箱子里 每次拿取数额最大的和最小的,给出 最大-最小  的钱. 问n天总共要给出多少钱. 思路分析: multiset 上直接进行模拟 注意要使用long lo ...

  9. 记两个std接口equal_range,set_difference

    1.equal_range equal_range是C++ STL中的一种二分查找的算法,试图在已排序的[first,last)中寻找value,它返回一对迭代器i和j,其中i是在不破坏次序的前提下, ...

随机推荐

  1. saas简介

    SaaS是Software-as-a-Service(软件即服务)的简称,随着互联网技术的发展和应用软件的成熟, 在21世纪开始兴起的一种完全创新的软件应用模式.它与“on-demand softwa ...

  2. js获取单选按钮的值

    function a(){ var v=document.getElementsByName("radio"); ;i<v.length;i++){ if(v[i].chec ...

  3. EXCEL的导入导出

    using System; using System.Data; using System.Data.OleDb; using System.IO; namespace COMMON { public ...

  4. js 常见混乱

    slice(begin.end) 复制出一个新的数组或是一个新的字符串,其中end 不包括end本身 splice(begin,howmany,item1....itemn) 更改原先的array 会 ...

  5. 再次完善了 WASPCN for Matlab

    前段时间有多个网友询问在64位Matlab中如何使用WASPCN(水和蒸汽性质计算软件)的方法,一直没能给出解决方案. 最近自己有个项目也需要在64位Matlab中如何使用WASPCN(水和蒸汽性质计 ...

  6. 写了一个基于React+Redux的仿Github进度条

    曾经实现过Angular版,这次感觉用了高大上的React却写了更多的代码,需要的配置也更多了,有利有弊吧. 但这个“导航条问题”很有意思,涉及到在Redux中写timer,其实我很困惑,到底如何完美 ...

  7. (转)Linux下root密码丢失和运行级别错误的解决办法

    我们知道,root用户在Linux中是相当重要的,其地位如同Windows中的Adminstrator 有了root权限我们还能修改其他用户的密码,可是,如果root用户的密码丢失该怎么办? 不用担心 ...

  8. 最小和(min)

    题目描述: N 个数排成一排,你可以任意选择连续的若干个数,算出它们的和.问该如何选择才能 使得和的绝对值最小. 如:N=8 时,8个数如下: 1    2    3     4    5    6 ...

  9. poj 3067 - Japan(树状数组)

    先按第一个数从大到小排序,相等的情况下,第二个数按照从大到小排序..... 预处理后,照着树状数组写就行了... 注意:k的最大值应取1000*1000 代码如下: include <cstdi ...

  10. Linux(centeros)安装weblogic10.3.6教程

    http://wenku.baidu.com/link?url=yCLXoDpK7AMdy1_TgGXDncY42Bz6ptdaNq58GdicFWqyI5i-fCvui6mFuIYDt6jkqSiY ...