map-有序 multimap-可重复 unordered_map-无序
#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-无序的更多相关文章
- stl vector、红黑树、set、multiset、map、multimap、迭代器失效、哈希表(hash_table)、hashset、hashmap、unordered_map、list
stl:即标准模板库,该库包含了诸多在计算机科学领域里所常用的基本数据结构和基本算法 六大组件: 容器.迭代器.算法.仿函数.空间配置器.迭代适配器 迭代器:迭代器(iterator)是一种抽象的设计 ...
- STL(六)——map、multimap
STL--map.multimap 文章目录 STL--map.multimap 关联容器与map的介绍 map与set的异同 map与multimap的异同 map类对象的构造 map添加元素 ma ...
- 4.3 map和multimap
使用map multimap必须包含头文件map *:multimap 1)multimap定义 template<class Key,class Pred=less<Key>,cl ...
- 使用multimap创建重复键关联容器
在“使用 <map> 库创建关联容器”一文中,我们讨论了标准库中的 map 关联容器.但那只是 map 容器的一部分.标准库还定义了一个 multimap 容器,它与 map 类似,所不同 ...
- STL的基本使用之关联容器:map和multiMap的基本使用
STL的基本使用之关联容器:map和multiMap的基本使用 简介 map 和 multimap 内部也都是使用红黑树来实现,他们存储的是键值对,并且会自动将元素的key进行排序.两者不同在于map ...
- STL标准库-容器-map和multimap
技术在于交流.沟通,本文为博主原创文章转载请注明出处并保持作品的完整性 map与multimap为关联容器,结构如下 map底层实现依然是rb_tree 他的data可以改,但是key不能改,因此ma ...
- 【C++ STL】Map和Multimap
1.结构 Map和multimap将key/value pair(键值/实值 队组)当作元素,进行管理.他们根据key的排序准则将元素排序.multimap允许重复元素,map不允许. 元素要求: k ...
- STL学习笔记— —容器map和multimap
简单介绍 在头文件<map> 中定义 namespace std { template <typename Key, typename T, typename Compare = l ...
- C++标准库分析总结(六)——<Map、Multimap、Set、Multiset设计原则>
关联容器我们可以看做是一个小型的数据库,它就是用key找value,编译器底层对于关联容器的实现有两种:红黑树(Red-Block tree)和哈希表(hash table,散列表). 一.红黑树简单 ...
- STL之Map和multimap容器
1.Map和multimap容器 1)map是标准的关联式容器,一个map是一个键值对序列,即(key,value)对.它提供基于key的快速检索能力. 2)map中key值是唯一的.集合中的元素按一 ...
随机推荐
- npm那些事儿
npm,Node Package Manager,是node.js的模块依赖管理工具,安装nodejs时,一般会附带npm包管理工具. 一.npm相关1.npm的用途 能解决NodeJS代码部署上的很 ...
- Thinkphp3.2.3加载外部类并调用类里面的方法 获取token
例如:加载七牛上传类(thinkphp自带的) $qiniu = new \Think\Upload\Driver\Qiniu\QiniuStorage($setting['driverConfig' ...
- Egret--添加一个精灵事件
class Hello extends egret.DisplayObjectContainer{ //入口函数 private onAddStage(event:egret.Event){ //打开 ...
- idea 自定义注释模板
一.类注释模板 打开Preferences Editor -> File and Code Templates -> Files -> Class 效果图: 注释模板 /** * @ ...
- 《Linux内核原理与分析》第一周作业 20189210
实验一 Linux系统简介 这一节主要学习了Linux的历史,Linux有关的重要人物以及学习Linux的方法,Linux和Windows的区别.其中学到了LInux中的应用程序大都为开源自由的软件, ...
- vcs编译verilog/sysverilog并执行
命令: sverilog:表示支持systemverilog,如果只编译verilog不需要加 test.sv :这个可以是一个systemverilog/verilog文件,也可以是一个filel ...
- 学习虚拟机时Vbox提示硬件加速不可用时应该怎么办?
也不知大家在安装或使用虚拟机时有没有出现过这样的现象?Vbox提示硬件加速不可用? 在学习Java和安装虚拟机时,自己的电脑上出现Vbox提示Vt-x硬件加速不可用,但后也知道了方法怎么弄! 方法及步 ...
- 区块链侧链应用开发平台Asch节点安装及区块生产教程
1 系统要求 必须是linux系统 必须有公网ip 建议使用ubuntu 14.04 64位 建议内存1G以上 建议带宽2Mb以上 2 安装 2.1 下载 wget https://www.asch. ...
- 无法登陆mysql user用户
- Mysqlbinlog解析工具
Mysql的binlog日志作用是用来记录mysql内部增删改查等对mysql数据库有更新的内容的记录(对数据库的改动),对数据库的查询select或show等不会被binlog日志记录;主要用于数据 ...