#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <algorithm>
using namespace std; void OutPut(char val)
{
cout << val << ' ';
} int main(int argc, char const *argv[])
{
vector<char> cVec;
cVec.push_back('Z');
cVec.push_back('D');
cVec.push_back('W');
cVec.push_back('S');
cVec.push_back('J');
cVec.push_back('A');
cVec.push_back('U'); cout << "用C++11 for(:)进行遍历" << endl;
cout << "向量排序前:\n";
for(auto x : cVec){
OutPut(x);
} // algorithm内的函数模板 底层还是for(begin,!=end)
cout << endl << endl << "用algorithm内的函数模板for_each进行遍历:" << endl;
for_each(cVec.begin(), cVec.end(), [](char val){cout << val << ' ';});
//for_each(cVec.begin(), cVec.end(), OutPut); // 排序
sort(cVec.begin(), cVec.end());
cout << endl << endl << "向量排序后:\n";
for(auto x : cVec){
OutPut(x);
}
// for_each(cVec.begin(), cVec.end(), OutPut); // algorithm内的函数模板 // map
cout << endl;
cout << endl;
cout << "map示例:" << endl;
map<int, int> imap;
//multimap<int, int> imap;
//unordered_map<int, int> imap;
//imap.insert(unordered_map<int, int>::value_type(100, 1000)); // 三种方式插入
imap.insert(make_pair(1, 10));
imap.insert(make_pair(4, 40));
imap.insert(make_pair(5, 50));
imap.insert(make_pair(9, 90));
imap.insert(map<int, int>::value_type(8, 800));
imap.insert(pair<int,int>(2,20)); // 如果需要更改值的话,用引用for(auto& it : imap)
for(auto it : imap)
{
cout << "Key:" << it.first << " --> Value:" << it.second << "\n";
} cout << endl;
system("pause");
return 0;
}

map-有序 multimap-可重复 unordered_map-无序的更多相关文章

  1. stl vector、红黑树、set、multiset、map、multimap、迭代器失效、哈希表(hash_table)、hashset、hashmap、unordered_map、list

    stl:即标准模板库,该库包含了诸多在计算机科学领域里所常用的基本数据结构和基本算法 六大组件: 容器.迭代器.算法.仿函数.空间配置器.迭代适配器 迭代器:迭代器(iterator)是一种抽象的设计 ...

  2. STL(六)——map、multimap

    STL--map.multimap 文章目录 STL--map.multimap 关联容器与map的介绍 map与set的异同 map与multimap的异同 map类对象的构造 map添加元素 ma ...

  3. 4.3 map和multimap

    使用map multimap必须包含头文件map *:multimap 1)multimap定义 template<class Key,class Pred=less<Key>,cl ...

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

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

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

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

  6. STL标准库-容器-map和multimap

    技术在于交流.沟通,本文为博主原创文章转载请注明出处并保持作品的完整性 map与multimap为关联容器,结构如下 map底层实现依然是rb_tree 他的data可以改,但是key不能改,因此ma ...

  7. 【C++ STL】Map和Multimap

    1.结构 Map和multimap将key/value pair(键值/实值 队组)当作元素,进行管理.他们根据key的排序准则将元素排序.multimap允许重复元素,map不允许. 元素要求: k ...

  8. STL学习笔记— —容器map和multimap

    简单介绍 在头文件<map> 中定义 namespace std { template <typename Key, typename T, typename Compare = l ...

  9. C++标准库分析总结(六)——<Map、Multimap、Set、Multiset设计原则>

    关联容器我们可以看做是一个小型的数据库,它就是用key找value,编译器底层对于关联容器的实现有两种:红黑树(Red-Block tree)和哈希表(hash table,散列表). 一.红黑树简单 ...

  10. STL之Map和multimap容器

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

随机推荐

  1. selenium之使用chrome浏览器测试(附chromedriver与chrome的对应关系表)

    https://www.cnblogs.com/JHblogs/p/7699951.html

  2. Jupyter notbook& REVEAL.JS& nbconvert 使用jupyter notebook制作slides

    使用Jupyter notebook作为slide主要有两个方面: 在运行notebook 的时候可以幻灯片播放 这样幻灯片就有了notebook可交互的功能,而notebook就有了幻灯片全屏容易分 ...

  3. day13_H5_CSS_1

    一.标签.HTML是可以被浏览器解析的一套规则 1.a标签:他是主动闭合标签,表现形式<a href="http://www.baidu.com">baidu<a ...

  4. react-native-splash-screen 插件 android 系统app崩溃问题

    问题 react-native版本 0.53.3 react-native-splash-screen版本 3.0.6 一切配置妥当后出现如下问题: 在android studio里的调试报错为and ...

  5. JS对象2

    1.Date对象 创建对象 //方法1:不指定参数 var nowd1=new Date(); alert(nowd1.toLocaleString( )); //方法2:参数为日期字符串 var n ...

  6. vue 监听路由变化

    方法一:通过 watch // 监听,当路由发生变化的时候执行 watch:{ $route(to,from){ console.log(to.path); } }, 或 // 监听,当路由发生变化的 ...

  7. Jmeter响应数据中文乱码

    在用Jmeter测试的时候吸纳供应数据如果出现中文乱码解决方法: 1.如下图在Content encoding输入框内输入  UTF-8

  8. RMAN备份filesperset用法

    用filesperset控制备份集的尺寸 当指定filesperset参数时,rman比较filesperset与自动计算出来的值(对每个已分配通道的文件数目) 并取其中较小的那个值来保证所有的通道被 ...

  9. Redis之基本使用

    基本介绍 Redis是一种key-value存储形式的非关系型数据库,也是一个强大的内存型存储系统,但是它比传统的Memcached 更灵活,支持更多的数据类型,同时也可以持久化. 支持的数据类型 先 ...

  10. PySe-007-解决“Chrome正在受到自动软件的控制”

    python使用selenium启动chrome的代码如下所示: #!/usr/local/bin/python # -*- coding: utf-8 -*- from selenium impor ...