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. boostrapt的二级下拉菜单

    <!DOCTYPE html><html> <head> <meta charset="UTF-8"> <meta conte ...

  2. js判断手指的上滑,下滑,左滑,右滑,事件监听

    原理:1:当开始一个touchstart事件的时候,获取此刻手指的横坐标startX和staerY: 2:当触发touchmove事件的时候,再获取此时手指的横坐标moveEndX和纵坐标moveEn ...

  3. python标准库中socket模块详解

    包含原理就是tcp的三次握手 http://www.lybbn.cn/data/datas.php?yw=71 这篇讲到了socket和django的联系 https://www.cnblogs.co ...

  4. 书法字帖 PDF转化为可打印PDF

    书法类的PDF,因为底色是黑色的,打印起来特别费墨,所以需要转化成白底黑字的文件, 才好打印. 1)用 pdfbox 的 ExtractImages 命令,抽出所有的图片 https://pdfbox ...

  5. Python如何发布程序

    https://blog.csdn.net/wem603947175/article/details/81589729

  6. navicat和 plsql 连接oracle数据库 总结

    打开 navicat  -->工具-->选项-->oci   右侧选择oci.dll 的路径 默认 在 navicat的安装目录下有一个 instantclient 的文件夹 直接选 ...

  7. android -------- Data Binding的使用(一)

    Google推出自己官方的数据绑定框架Data Binding Library 已经很久了,很多企业也在使用 面试的时候也有问到,所以也去学习了一番,特来分享一下,希望对各位有所帮助 描述: Data ...

  8. win10+cpu+tensorflow+pycharm

    1.安装64位的python3.5 选择windowsx86-64 executable installer安装 2.安装tensorflow cmd->进入到安装python的Scripts文 ...

  9. vue select的change事件,将点击过的城市名存在数组中,下次调用不需要再调用接口

    <template> <div id="body" class="application" v-show="show" v ...

  10. 多线程总结2之volatile和synchronized(转)

    本文转自 http://www.jasongj.com/java/thread_safe/ 一.多线程编程中的三个核心概念 本篇文章将从这三个问题出发,结合实例详解volatile如何保证可见性及一定 ...