当前位置:网站首页>STL map operation
STL map operation
2022-07-23 15:18:00 【joker_ 0030】
#include<iostream>
#include<map>
#include<algorithm>
#include<functional>
using namespace std;
void MapDelete()
{
typedef pair<int, char> in_pair;
map<int, char> db;// Result default key value sorting from small to large .
//map<int, char,greater<int>> db;// The result is modified to sort the key values from large to small .
db.insert(in_pair(1, 'a'));
db.insert(in_pair(2, 'a'));
db.insert(in_pair(3, 'a'));
db.insert(in_pair(4, 'a'));
Iterative output
//map<int, char>::iterator ite = db.begin();
map<int, char,greater<int>>::iterator ite = db.begin();// The result is modified to sort the key values from large to small .
//ite++;
//ite++;
Delete
db.erase(ite);// The delete key value is 3 Value
//db.erase(3);// The delete key value is 3 Value
db.erase(ite, db.end());// The delete key value is 3 Value to the end of the tail .
//ite = db.begin();// After modification, the iterator will fail , So we need to restate .
/*for ( ite ; ite != db.end(); ite++)
{
cout << ite->first << " " << ite->second << endl;
}*/
// Iterator lookup .
map<int, char>::iterator ite = db.begin();
map<int, char>::iterator ite1 = db.find(2);// lookup 2 This key value , Finding it will return 2 The iterator at the location .
if (db.end() == db.find(6)) // If there is no 6 This key value , be find Return to the last element end()( Not the last key , But next to the actual tail element end()), The operation will crash .
{
cout << "OK" << endl;
}
cout << ite1->first << " " << ite1->second << endl;
cout << db.lower_bound(3)->first << endl;// Returns the parameter key The location of , This position is greater than or equal to key:key<=pos.
cout << db.upper_bound(3)->first << endl;// Returns the parameter key Next position of , This position is greater than key:key<pos.
}
int main()
{
//MapOther();
MapDelete();
system("pause");
return 0;
}
* Key values cannot be modified ( Caused by red and black trees ), The actual value can be modified , Changing the key value will change the whole structure .
边栏推荐
- ESP三相SVPWM控制器的simulink仿真
- turbo编译码误码率性能matlab仿真
- Live classroom system 01 database table design
- bgp基本配置
- Matlab simulation of solving multi-objective optimal value based on PSO optimization
- C# 计算某个字符在字符串中出现的次数
- 上小学之前要学会的本领指引
- MariaDB 数据库升级版本
- [heuristic divide and conquer] the inverse idea of heuristic merging
- c语言:深度刨析const关键字
猜你喜欢

Educational Codeforces Round 132 (Rated for Div. 2) D. Rorororobot

初识C语言函数

什么是服务器托管及和虚拟主机的区别

Linux: analysis of the basic use of vim editor

Head pose estimation principle and visualization_ Loveliuzz's blog - Programmer's Homestead_ Head posture estimation

查找论文源代码

【OpenCV 例程200篇】225. 特征提取之傅里叶描述子

The exclamation point of vscode +tab shortcut key cannot be used, and the solution to the problem of a-soul-live2d plug-in

numpy和pytorch的版本对应关系

Force buckle monotone stack
随机推荐
String与Integer互相转换
OPNsense – 多功能高可靠易使用的防火墙(二)
Chapter 4 use%rest API classes create rest services
day18
头部姿态估计原理及可视化_loveliuzz的博客-程序员宅基地_头部姿态估计
Kettle implémente une connexion de base de données partagée et insère une instance de composant de mise à jour
ERP管理系统在装备制造企业管理中的应用
AVX指令集加速矩阵乘法
Linked list review!
MySQL 常用命令
Skills to learn before going to primary school
Error | cannot read property '_ normalized‘ of undefined
Cloud native observability tracking technology in the eyes of Baidu engineers
Selenium in the crawler realizes automatic collection of CSDN bloggers' articles
[turn] functional area division based on poi ()
【7.16】代码源 -【数组划分】【拆拆】【选数2】【最大公约数】
如何加速矩阵乘法——优化GEMM (CPU单线程篇)
581. Shortest unordered continuous subarray
初识C语言函数
什么是Promise?Promise有什么好处