#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. Team

    队名 正义联盟 团队成员 211606301 蔡振翼(队长) 211606445 肖志豪 211606382 吴文清 211606370 刘华强 211605240 谢孟轩 211614269 林凯 ...

  2. 入门级----黑盒测试、白盒测试、手工测试、自动化测试、探索性测试、单元测试、性能测试、数据库性能、压力测试、安全性测试、SQL注入、缓冲区溢出、环境测试

    黑盒测试 黑盒测试把产品软件当成是一个黑箱子,只有出口和入口,测试过程中只要知道往黑盒中输入什么东西,知道黑盒会出来什么结果就可以了,不需要了解黑箱子里面是如果做的. 即测试人员不用费神去理解软件里面 ...

  3. 软件工程团队:Spring计划会议及详细计划表

     极限挑战! 小组Spring计划表: 11.15 进行软件需求分析,了解调查社会背景,确定要编写的软件,分配各小组成员的任务.确定小组会议每天召开地点时间. 3h 11.16 将任务进一步精确分配, ...

  4. idea使用配置

    一,打开窗口多行显示, Window→Editor Tabs→Tabs Placement→Show Tabs in Single Row 取消选中后即可在多行显示 2 .还可以自行设置打开文件窗口数 ...

  5. AngularJS_简介、特性及基本使用_及其工作原理

    转自:angularJS 的工作原理 转自:通过<script>标签引入到 HTML 中,那么此时 Angular 就做为一个普通的 DOM 节点等待浏览器解析 当浏览器解析到这个节点时, ...

  6. Sun SPARC Enterprise M5000 启动步骤

    1.串口线与笔记本连接(需在笔记本上安装串口线的驱动程序,usb口接笔记本,网线水晶头接M5000)2.接通电源.此时XSCF卡充电,自检,前面板XSCF等闪烁.3.登录超级终端,注意波特率要跟主机匹 ...

  7. Random类 一般跟生成随机数有关

    public class MyRandom extends Random{ public static void main(String[] args) { // 随机数,生产随机数 // java提 ...

  8. type显示的是访问类型,是较为重要的一个指标,结果值从好到坏依次是: system > const > eq_ref > ref > fulltext > ref_or_null > index_merge > unique_subquery > index_subquery > range > index > ALL ,一般来说,得保证查询至少达到range级别,最好能达到ref。 作者:高

    MySQL EXPLAIN详解 - 简书 https://www.jianshu.com/p/ea3fc71fdc45 type显示的是访问类型,是较为重要的一个指标,结果值从好到坏依次是: syst ...

  9. Win10问题汇总

    1.重置网络连接命令 netsh winsock reset ipconfig /flushdns 2.WIN10去除我的电脑上面的6个文件夹 把下面代码复制,保存到.reg中,然后执行即可(修改注册 ...

  10. kubernetes安装

    本文主要参考自: https://blog.csdn.net/real_myth/article/details/78719244 还有一份更适合在生产环境使用的超强高可用(多master,nginx ...