如何根据 c++ 中键的递增/减顺序打印哈希映射的值
How to print value of a hash map according to increasing/decreasing order of key in c++?
如果我们有一张地图,
map <int,int> m;
和以下键值对 (-2,3) , (-14,8) , (4,8), (6,12) , (3,76)
现在,如果我们想按键的递增顺序打印值,那么如何打印?
o/p
83 76 8 12
默认情况下,std::map
中的键是有序的(使用 operator<
)。您可以遍历地图:
for (std::map<int, int>::iterator i = m.begin(); i != m.end(); i++)
{
cout << i->second << "n";
}
相关文章:
- 如何在C++中递归地按相反顺序打印集合
- 首先按给定顺序打印所有数字,然后使用 Array 打印所有字符和其他符号
- 按字母顺序打印存储在字符数组中的信息
- 视觉C++未按所需顺序打印
- C++使用相反的顺序打印带有逗号的列表
- C/C++ - 用于按顺序打印数字的 sem_t 类型的单个信号量
- 如何以相反顺序C 打印整数的单个数字
- 我不知道如何创建一个以数字/字母顺序打印出我的整数或字符串的程序
- 在 C Linux 中使用三个线程使用信号量同步按顺序打印 3 4 5 50 次
- 以相反的顺序打印链表的后半部分
- 我如何附加双链接以指向正确的节点,以相反的顺序打印
- 按字母顺序打印结构输入C
- 按顺序打印时遇到问题,二叉树的后顺序等
- 按特定顺序打印队列
- 输出未按正确的顺序打印
- 按字典顺序打印给定字符串的所有字母组合的算法
- 使用基于范围的 for 循环以相反的顺序打印矢量
- C++链表-按排序顺序打印
- 我如何使用C ++以相反的顺序打印此单个链表中的元素
- 如何使链接列表按字母顺序打印其内容