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. NGINX:漫谈优化

    优化那些事儿 生产环境下网站做前期的优化肯定是比不可少的,简单来说就是用同等条件的硬件资源,处理更多的网站业务,大程度提供网站业务处理能力:前辈留下的实战经验可都是财富,好多坑只有踩过才知道痛,下面就 ...

  2. JavaScript高级程序设计第三版学习笔记(一)之数据类型区分详谈

    null.NaN.undefined三者的区别是什么? 在初次接触到JavaScript的时候,傻傻的分不清null.NaN.undefined三者到底区别何在,在实际的项目开发中也因为这个问题而困惑 ...

  3. Feed系统架构资料收集(转)

    add by zhj:有些链接已经失效,后续会修改. 原文:http://blog.csdn.net/zhangzhaokun/article/details/7834797 完全用nosql轻松打造 ...

  4. 分布式版本管理git学习资料整理推荐

    一.什么是git? Git is a free and open source distributed version control system designed to handle everyt ...

  5. 知识点1-树状数组[带poj Stars作为巩固]

    转自:https://blog.csdn.net/flushhip/article/details/79165701#commentBox 1.首先其中讲到了一个问题,就是如何求一个数的二进制表示的最 ...

  6. soapUi下载

    http://dl.eviware.com/list_soapui2.html http://smartbearsoftware.com/repository/eviware/jars/

  7. Ajax保留浏览器历史的两种解决方案(Hash&Pjax)

    总是在github down点东西,github整个界面做的不错,体验也很好~对于其中的源代码滑动的特效最为喜欢了~刚开始以为这个只是普通的ajax请求效果,但是发现这个特效能够导致浏览器地址栏跟随变 ...

  8. Android 压力测试工具Monkey

    原文地址http://www.syhm52.com/tools/17.html 一.Monkey定义探索软件测试工具有哪些,本文主要介绍Monkey工具.Monkey测试是Android平台自动化测试 ...

  9. macbook 蓝牙关闭按钮灰色的

    PRAM重置:1.关机,拔掉所有外设,只连接电源线2.按开机键,接着马上同时按住 command+option+p+r 键,按住后听到三次dang的开机音后放开3.电脑会自行启动,进到登录页面后点关机 ...

  10. python 中使用ConfigParser类修改配置文件

    配置文件的格式: [user] user_ip=127.0.0.1 user_name=testuser user_id=13 import ConfigParser conf = ConfigPar ...