非关联容器|hash|unordered_map/multimap,unordered_set/multiset
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;
}
|
|
#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的更多相关文章
- 关联容器:unordered_map详细介绍(附可运行代码)
介绍 1 特性 2 Hashtable和bucket 模版 1 迭代器 功能函数 1 构造函数 12示例代码 2 容量操作 21 size 22 empty 3 元素操作 31 find 32 ins ...
- 关联容器:unordered_map详细介绍
版权声明:博主辛辛苦苦码的字哦~转载注明一下啦~ https://blog.csdn.net/hk2291976/article/details/51037095 介绍 1 特性 2 Hashtabl ...
- unordered_map/unordered_set & unordered_multimap/unordered_multiset非关联容器
body, table{font-family: 微软雅黑; font-size: 10pt} table{border-collapse: collapse; border: solid gray; ...
- 09--STL关联容器(map/multimap)
一:map/multimap的简介 map是标准的关联式容器,一个map是一个键值对序列,即(key,value)对.它提供基于key的快速检索能力. map中key值是唯一的.集合中的元素按一定的顺 ...
- 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 ...
- STL的基本使用之关联容器:map和multiMap的基本使用
STL的基本使用之关联容器:map和multiMap的基本使用 简介 map 和 multimap 内部也都是使用红黑树来实现,他们存储的是键值对,并且会自动将元素的key进行排序.两者不同在于map ...
- STL 笔记(二) 关联容器 map、set、multimap 和 multimap
STL 关联容器简单介绍 关联容器即 key-value 键值对容器,依靠 key 来存储和读取元素. 在 STL 中,有四种关联容器,各自是: map 键值对 key-value 存储,key 不可 ...
- 使用multimap创建重复键关联容器
在“使用 <map> 库创建关联容器”一文中,我们讨论了标准库中的 map 关联容器.但那只是 map 容器的一部分.标准库还定义了一个 multimap 容器,它与 map 类似,所不同 ...
- STL的基本使用之关联容器:set和multiSet的基本使用
STL的基本使用之关联容器:set和multiSet的基本使用 简介 set 和 multiSet 内部都是使用红黑树来实现,会自动将元素进行排序.两者不同在于set 不允许重复,而multiSet ...
随机推荐
- 转载:Linux内核调试方法
转载文章请注明作者和二维码及全文信息. 转自:http://blog.csdn.net/swingwang/article/details/72331196 不会编程的程序员,不是好的架构师,编程和内 ...
- JSP学习(第一课)
JSP页面组成: 比如: 打开网页,右键查看源代码: 打开网页: 注意: <%!%>里面定义的属性是成员属性,相当于类的属性,方法相当于是全局的方法,相当于是类里面的方法.但是它是不可以进 ...
- Linux下tomcat启动项目原因排查
先停掉tomcat服务器: 然后把文件删除: 这时候启动服务器: 看下有没有启动成功: 接着把重新优化过的代码用X ftp传上去. 等几分钟就可以. 如果老是出现问题,就去catalina.out文件 ...
- centos shell编程3【告警系统】 没有服务器端和客户端的概念 main.sh mon.conf load.sh 502.sh mail.php mail.sh disk.sh 第三十七节课
centos shell编程3[告警系统] 没有服务器端和客户端的概念 main.sh mon.conf load.sh 502.sh mail.php mail.sh disk.sh 第三十七 ...
- YOGA Tablet 2 1371f 触屏失效,无声卡,蓝牙键盘都无法使用的解决办法
安装驱动! 下载地址 http://www.lenovocare.com.cn/Handler/Download.ashx?fileid=1234 安装后电源管理,声卡,触摸屏即可使用! 蓝牙键盘连接 ...
- httpclient接口测试完整用例以及获取信息的方法
原文地址https://blog.csdn.net/fhaohaizi/article/details/78088075 原文地址https://blog.csdn.net/fhaohaizi/art ...
- Qt 引用头文件 QT_BEGIN_NAMESPACE QT_END_NAMESPACE
Qt里面引入头文件的两种方式: 1. #include <QMdiArea> #include<QSplashScreen> 2. QT_BEGIN_NAMESPACE cla ...
- springcloud19---springCloudConfig
Spring-cloud-config : 统一管理配置的组件,不同的环境不同的管理(连接池.数据库配置不一样).不同时间需要动态调整配置(双十一最大连接数要大). 分布式配置也可以使用config或 ...
- 【知识总结】Activiti工作流学习入门
1. 我理解的工作流: 在工作中慢慢接触的业务流程,就向流程控制语言一样,一步一步都对应的不同的业务,但整体串联起来就是一个完整的业务.而且实际工作中尤其是在企业内部系统的研发中,确实需要对应许多审批 ...
- TED #07# How to inspire every child to be a lifelong reader
Alvin Irby: How to inspire every child to be a lifelong reader Prepare elementarykitchen tableforced ...