multiMap遍历方法
/*
multimap中的三种遍历方法
multimap中如果没有查找到相应元素,则返回的迭代器是依据该元素的排列顺序该键应该插入的位置
如果找不到,则方法一和方法二返回的两个迭代器应该相等
*/
#include <iostream>
#include <map>
#include <string>
#include <utility> using namespace std; int main()
{
multimap<string, string> mulMap;
mulMap.insert(make_pair("鲁迅", "朝花夕拾"));
mulMap.insert(make_pair("鲁迅", "阿Q正传"));
mulMap.insert(make_pair("鲁迅", "野草"));
mulMap.insert(make_pair("罗贯中", "三国演义"));
mulMap.insert(make_pair("罗贯中", "隋唐志传"));
mulMap.insert(make_pair("琼瑶", "还珠格格"));
mulMap.insert(make_pair("琼瑶", "情深深雨蒙蒙"));
typedef multimap<string, string>::iterator multiMapItor;
//方法一:推荐 string author("鲁迅");
cout << author << "的书籍有:" << endl;
pair<multiMapItor, multiMapItor> pos = mulMap.equal_range(author);
while(pos.first != pos.second)
{
cout << pos.first->second << endl;
++pos.first;
}
cout << endl;
//方法二:
author.assign("罗贯中");
cout << author << "的书籍有:" << endl;
multiMapItor beg = mulMap.lower_bound(author);
multiMapItor end = mulMap.upper_bound(author);
while(beg != end)
{
cout << beg->second << endl;
++beg;
}
cout << endl;
//方法三:不推荐
author.assign("琼瑶");
cout << author << "的书籍有:" << endl;
typedef multimap<string, string>::size_type sz_type;
sz_type entries = mulMap.count(author);
multiMapItor itor = mulMap.find(author);
for(sz_type cnt = ; cnt != entries; ++cnt)
cout << (itor++)->second << endl; system("pause");
return ;
}
multiMap遍历方法的更多相关文章
- javase-常用三种遍历方法
javase-常用三种遍历方法 import java.util.ArrayList; import java.util.Iterator; import java.util.List; public ...
- Java中Map的三种遍历方法
Map的三种遍历方法: 1. 使用keySet遍历,while循环: 2. 使用entrySet遍历,while循环: 3. 使用for循环遍历. 告诉您们一个小秘密: (下↓面是测试代码,最爱看 ...
- Jquery中each的三种遍历方法
Jquery中each的三种遍历方法 $.post("urladdr", { "data" : "data" }, function(dat ...
- JavaScript、jQuery、fish的遍历方法(each、forEach)总结
起因 在工作中,需要在遍历的dom中找到第一个并做下操作然后退出遍历,我首先想到了用each方法,但由于无论是公用的jQuery组件还是公司的fish组件.我都忘记了怎么去退出遍历,所以就有了这篇帖子 ...
- Map的五种遍历方法
package com.jackey.topic; import java.util.ArrayList;import java.util.HashMap;import java.util.Itera ...
- python数据结构与算法——二叉树结构与遍历方法
先序遍历,中序遍历,后序遍历 ,区别在于三条核心语句的位置 层序遍历 采用队列的遍历操作第一次访问根,在访问根的左孩子,接着访问根的有孩子,然后下一层 自左向右一一访问同层的结点 # 先序遍历 # ...
- python 中 五种字典(dict)的遍历方法,实验法比较性能。
1 .背景: 想知道5种遍历方法,并且知道从性能角度考虑,使用哪种. 2.结论: 使用这种方式: for key,val in AutoDict.iteritems(): temp = "% ...
- C语言 数组做函数参数不传数组个数的遍历方法
//数组做函数参数不传数组个数的遍历方法 #include<stdio.h> #include<stdlib.h> #include<string.h> void ...
- java list三种遍历方法性能比較
从c/c++语言转向java开发,学习java语言list遍历的三种方法,顺便測试各种遍历方法的性能,測试方法为在ArrayList中插入1千万条记录,然后遍历ArrayList,发现了一个奇怪的现象 ...
随机推荐
- [Java]Spring框架
在这里学习Spring框架: >>spring&struts框架学习 >>spring >>Java回顾之Spring基础 >>IBM Java ...
- HDU 5835 Danganronpa 贪心
Danganronpa 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5835 Description Chisa Yukizome works as ...
- authentication unavailable: no polkit agent available to authenticate action 'org.libvirt.unix.manage'的问题解决
这个主要是WebVirtMgr的安装导致出现的错误,解决方法如下: 1.增加libvirtd用户组 groupadd libvirtd 2.设置用户到组 sudo usermod -a -G libv ...
- enode
WeText项目:一个基于.NET实现的DDD.CQRS与微服务架构的演示案例 WeText项目:一个基于.NET实现的DDD.CQRS与微服务架构的演示案例 https://mp.weixin.qq ...
- Go 导入当前项目下的包
其实和其他语言很类似 import ( "../controllers" //这里就是导入上一级目录中的controllers "./models&quo ...
- C#怎么通过一个按钮Button,实现点击这个按钮可以打开一个文件或者文件夹?
string path1 = @"d:\log.txt"; //打开D盘下的log.txt文件 System.Diagnostics.Process.Start(path1); ...
- [置顶] Redis String类型数据常用的16条命令总结
Redis String类型数据常用的16条命令总结 描述:String 类型是最简单的类型,一个Key对应一个Value,String类型是二进制安全的.Redis的String可以包含任何数据,比 ...
- <table>标签的结构和合并单元格的方法
1.<table>标签的结构 示例代码: <table border="1"> <caption>信息统计表</captio ...
- [Winform]WebKit.Net使用
摘要 在项目中使用了cefsharp,最后发现在触屏电脑上面,如果长按文本内容,会经常性的崩溃,发现是cefsharp的问题,最后也等不及了.然后就换了webkit.net这个开源的浏览器内核. 关于 ...
- Step Detector and Step Counter Sensors on Android
Step Detector and Step Counter Sensors on Android 时间 2014-03-31 11:56:00 Tech Droid 原文 http://techd ...