body, table{font-family: 微软雅黑; font-size: 10pt}
table{border-collapse: collapse; border: solid gray; border-width: 2px 0 2px 0;}
th{border: 1px solid gray; padding: 4px; background-color: #DDD;}
td{border: 1px solid gray; padding: 4px;}
tr:nth-child(2n){background-color: #f8f8f8;}

unordered_map & unordered_multimap

#include<iostream>
#include<unordered_map>
#include<string>
#include<iterator>
using namespace std;
int main()
{
        pair<int,string> arr[5]={
                pair<int,string>(1,"北京"),
                pair<int,string>(2,"上海"),
                pair<int,string>(2,"昆明"),
                pair<int,string>(4,"重庆"),
                pair<int,string>(3,"天津")
        };
        unordered_map<int ,string> test1(arr,arr+5);
        unordered_map<int ,string>::iterator it = test1.begin();
        for(;it!=test1.end();++it)
        {
                cout<<it->first<<" "<<it->second<<endl;
        }
        //无序map,不能使用less<>和greater<>来排序了
        cout<<"test unordered_multimap:"<<endl;
        unordered_multimap<int ,string> test2(arr,arr+5);
        for(auto& elem:test2)
        {
                cout<<elem.first<<" "<<elem.second<<endl;
        }
        cout<<"test random access:"<<endl;
        cout<<test1[1]<<endl;  // unordered_multimap不支持随机访问
        unordered_multimap<int,string>::iterator umit = test2.find(2);
        cout<<umit->first<<" "<<umit->second<<endl;
}

unordered_set & unordered_multiset
#include<iostream>
#include<unordered_set>
using namespace std;
int main()
{
        int arr[7] = {2,2,1,3,4,5,3};
        unordered_set<int> test1(arr,arr+7);
        for(auto& elem:test1)
                cout<<elem<<" ";
        cout<<endl;
        cout<<"test unordered_multiset"<<endl;
        unordered_multiset<int> test2(arr,arr+7);
        for(auto& elem:test2)
                cout<<elem<<" ";
        cout<<endl;
        unordered_multiset<int> test3(arr,arr+7);
        cout<<"test random access"<<endl;
        cout<<*(test2.find(3))<<endl;
        cout<<*(test2.find(2))<<endl;
        cout<<"value = 2 cnt:"<<test2.count(2)<<endl;
        return 0;
}

非关联容器|hash|unordered_map/multimap,unordered_set/multiset的更多相关文章

  1. 关联容器:unordered_map详细介绍(附可运行代码)

    介绍 1 特性 2 Hashtable和bucket 模版 1 迭代器 功能函数 1 构造函数 12示例代码 2 容量操作 21 size 22 empty 3 元素操作 31 find 32 ins ...

  2. 关联容器:unordered_map详细介绍

    版权声明:博主辛辛苦苦码的字哦~转载注明一下啦~ https://blog.csdn.net/hk2291976/article/details/51037095 介绍 1 特性 2 Hashtabl ...

  3. unordered_map/unordered_set & unordered_multimap/unordered_multiset非关联容器

    body, table{font-family: 微软雅黑; font-size: 10pt} table{border-collapse: collapse; border: solid gray; ...

  4. 09--STL关联容器(map/multimap)

    一:map/multimap的简介 map是标准的关联式容器,一个map是一个键值对序列,即(key,value)对.它提供基于key的快速检索能力. map中key值是唯一的.集合中的元素按一定的顺 ...

  5. STL set multiset map multimap unordered_set unordered_map example

    I decide to write to my blogs in English. When I meet something hard to depict, I'll add some Chines ...

  6. STL的基本使用之关联容器:map和multiMap的基本使用

    STL的基本使用之关联容器:map和multiMap的基本使用 简介 map 和 multimap 内部也都是使用红黑树来实现,他们存储的是键值对,并且会自动将元素的key进行排序.两者不同在于map ...

  7. STL 笔记(二) 关联容器 map、set、multimap 和 multimap

    STL 关联容器简单介绍 关联容器即 key-value 键值对容器,依靠 key 来存储和读取元素. 在 STL 中,有四种关联容器,各自是: map 键值对 key-value 存储,key 不可 ...

  8. 使用multimap创建重复键关联容器

    在“使用 <map> 库创建关联容器”一文中,我们讨论了标准库中的 map 关联容器.但那只是 map 容器的一部分.标准库还定义了一个 multimap 容器,它与 map 类似,所不同 ...

  9. STL的基本使用之关联容器:set和multiSet的基本使用

    STL的基本使用之关联容器:set和multiSet的基本使用 简介 set 和 multiSet 内部都是使用红黑树来实现,会自动将元素进行排序.两者不同在于set 不允许重复,而multiSet ...

随机推荐

  1. python练习汇总

    1.99乘法表 """ 题目:输出 9*9 乘法口诀表. """ for i in range(1, 10): print () for j ...

  2. Hadoop MapReduce Task的进程模型与Spark Task的线程模型

    Hadoop的MapReduce的Map Task和Reduce Task都是进程级别的:而Spark Task则是基于线程模型的. 多进程模型和多线程模型 所谓的多进程模型和多线程模型,指的是同一个 ...

  3. Hyperledger Fabric 开发环境搭建 centos7系统

    一.安装GO语言 下载最新版的go 打开Terminal,输入命令(以下命令都是以root管理员的角色进行的) su 输入密码:***** wget https://storage.googleapi ...

  4. Deep Learning(1)

    深度学习是机器学习研究中的一个新的领域,其动机在于建立.模拟人脑进行分析学习的神经网络,它模仿人脑的机制来解释数据,例如图像,声音和文本.深度学习是无监督学习的一种. 深度学习的概念源于人工神经网络的 ...

  5. linux centos7 erlang rabbitmq安装

    最终的安装目录为/opt/erlang 和 /opt/rabbitmq wget http://erlang.org/download/otp_src_21.0.tar.gztar zxvf otp_ ...

  6. Smarty 函数

    html_checkboxes 自定义函数 html_checkboxes 根据给定的数据创建复选按钮组. 该函数可以指定哪些元素被选定. 要么必须指定 values 和 ouput 属性,要么指定 ...

  7. MyBatis—mapper.xml映射配置

    SQL文件映射(mapper文件),几个顶级元素的配置: mapper元素:根节点只有一个属性namespace(命名空间)作用: 1:用于区分不同的mapper,全局唯一. 2:绑定DAO接口,即面 ...

  8. 通过自动回复机器人学Mybatis:MySQL脚本 + db >> dao >> service >> servlet

    留着参考 makeData.sql delimiter // create procedure make_data() begin declare i int ; do insert into mes ...

  9. python基础学习十 logging模块详细使用【转载】

    很多程序都有记录日志的需求,并且日志中包含的信息既有正常的程序访问日志,还可能有错误.警告等信息输出,python的logging模块提供了标准的日志接口,你可以通过它存储各种格式的日志,主要用于输出 ...

  10. 前端学习笔记之CSS文档流

    先引用一段W3C的文档: 9.3 Positioning schemes In CSS 2.1, a box may be laid out according to three positionin ...