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;
}

unordered_map/unordered_set & unordered_multimap/unordered_multiset非关联容器的更多相关文章

  1. 非关联容器|hash|unordered_map/multimap,unordered_set/multiset

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

  2. [C++ Primer] : 第11章: 关联容器

    目录 使用关联容器 关联容器概述 关联容器操作 无序容器 使用关联容器 关联容器与顺序容器有着根本的不同: 关联容器中的元素是按关键字来保存和访问的, 按顺序容器中的元素是按它们在容器中的位置来顺序保 ...

  3. Chapter11(关联容器)--C++Prime笔记

    1.关联容器: map关键字-值对,经常被称为关联数组 set中每个元素只有一个关键字,即只保存关键字的容器 ①允许重复的关键字的容器名字都包含multi. ②不保持关键字顺序存储的容器的名字都以但粗 ...

  4. STL关联容器总结

    有序的都不带unordered,即如下: set multiset map multimap 其中带multi的表示关键字可以重复 无序的带unordered,如下: unordered_map un ...

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

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

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

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

  7. C++ primer 11章关联容器

    map set multimap (关键字可重复出现) multiset 无序 unordered_map  (用哈希函数组织的map) unordered_set unordered_multima ...

  8. c++ 标准库的各种容器(vector,deque,map,set,unordered_map,unordered_set,list)的性能考虑

    转自:http://blog.csdn.net/truexf/article/details/17303263 一.vector vector采用一段连续的内存来存储其元素,向vector添加元素的时 ...

  9. C++基础之关联容器

    关联容器 关联容器和顺序容器的本质区别:关联容器是通过键存取和读取元素.顺序容器通过元素在容器中的位置顺序存储和访问元素.因此,关联容器不提供front.push_front.pop_front.ba ...

随机推荐

  1. 第 8 章 容器网络 - 050 - 创建 overlay 网络

    在 host1 中创建 overlay 网络 ov_net1: docker network create -d overlay ov_net1 -d overlay 指定 driver 为 over ...

  2. spring cloud ----> RibbonClient设置的熔断器Hystrix不起作用

    Ribbon spring.io 官网的简介: Ribbon is a client side load balancer which gives you a lot of control over ...

  3. Linux上rsync配置

    一.服务器端配置1.rsyncd.conf文件说明uid = rsync     #用户,用来控制用户访问模块目录的读写权限gid = rsync     #组,用来控制组访问模块目录的读写权限use ...

  4. 20180428 xlVBA自动设置成绩条行高

    '自动设置行高 传入工作表Sht 和 每页打印的行数RowsInOnePage Public Sub AutoSetRowHeight(ByVal Sht As Worksheet, Optional ...

  5. 11月24日 layouts and rendering in rails(部分没有看)

    http://guides.rubyonrails.org/layouts_and_rendering.html  中文 This guide covers the basic layout feat ...

  6. P2375 [NOI2014]动物园

    考虑kmp. 这个题的主要问题就在于怎样使复杂度是正确的O(n). 可以先预处理一个数组cnt[]表示不考虑不能相交这个限制,有多少个border. 这个东西其实也就是fail树上的深度. 然后考虑怎 ...

  7. genymotio安装apk包提示 ...abi ...cpu

    下载 Genymotion-ARM-Translation_v1.1 (1).zip 地址:http://qc1.androidfilehost.com/dl/Q-YDDKt4QaFNvKh62ppO ...

  8. Linux系统中文件定位与查找

    Linux系统中文件查找 关键词 文件查找 | find | locate 本文主要介绍有关文件查找的两个命令——find和locate,以及压缩打包的命令——compress, gzip,bzip2 ...

  9. windows远程以及文件共享方法总结

    文件共享部分 紧接着下一步[允许使用空密码] 参考这个链接 https://jingyan.baidu.com/article/7f766dafa8c5ee4100e1d071.html 在我们使用w ...

  10. bzoj-2038-莫队

    2038: [2009国家集训队]小Z的袜子(hose) Time Limit: 20 Sec  Memory Limit: 259 MBSubmit: 15784  Solved: 7164[Sub ...