当前位置:网站首页>关于map对key自定义排序
关于map对key自定义排序
2022-07-30 05:45:00 【尹平华】
map对key默认是从小到大排序
也可以自定义排序
#include <iostream>
#include <map>
#include <string>
// 定义自己std::map比较器
template<class _Ty>
struct PLess
{
// functor for operator<
bool operator()(const _Ty& pLeft, const _Ty& pRight) const
{
// apply operator< to operands
return pLeft > pRight; // 这个比较器与默认比较器不同的地方
}
};
int main()
{
// 如果Key是一个指针, 为了正确排序, 需要自己定义比较器对象
std::map<int, int, PLess<int>> datas;
datas[1] = 3;
datas[2] = 2;
datas[3] = 1;
return 0;
}
边栏推荐
- 对于国内数据交换平台的分析
- 十一、Kotlin进阶学习:1、集合;2、List操作;3、可变集合——MutableList;4、Set;5、Map;6、MutableMap;
- Biome-BGC 生态系统模型与应用
- Mysql client common exception analysis
- 十六、Kotlin进阶学习:协程详细学习。
- The application of Meta analysis in the field of ecological environment
- OpenCV中(rows,cols)与图像(x,y)
- QT每周技巧(2)~~~~~~~~~界面按钮
- The types of data structures and MySQL index
- 六、Kotlin基础学习:函数
猜你喜欢

Detailed explanation of regular expression syntax and practical examples

Based on R language geographic weighted regression, principal component analysis, discriminant analysis and other spatial heterogeneity data analysis

第一个WebAssembly程序

什么是过拟合、欠拟合现象以及如何缓解?

CNN经典模型发展进程

nodejs PM2监控及报警邮件发送(二)

QT串口动态实时显示大量数据波形曲线(五)========“最终完美解决版”

遥感、GIS和GPS技术在水文、气象、灾害、生态、环境及卫生等应用

二十一、Kotlin进阶学习:实现简单的网络访问封装

Flink-流/批/OLAP一体得到Flink引擎
随机推荐
CNN经典模型发展进程
HSPF 模型应用
标准化(Normalization)知识点总结
Jdbc & Mysql timeout分析
点云统计滤波理解
User password encryption using Bcrypt instead of MD5, SHA1 and SHA256
QT每周技巧(3)~~~~~~~~~串口添加
抽象工厂模式(Swift 实现)
SQL Server Installation Tutorial
无人机生态环境监测、图像处理与GIS数据分析
常用损失函数(一):Focal Loss
How does MATLAB display nii file slice information in the image?
R-GIS: 如何用R语言实现GIS地理空间分析及模型预测
【青岛站】SWAT模型高阶应用暨无资料地区建模、不确定分析与气候变化、土地利用对面源污染影响模型改进及案例分析研讨
The first WebAssembly program
QT连载4:基于QT和STM32H750的LORA试验平台(3)
海量遥感数据处理与GEE云计算技术应用【基础、进阶】
边境的悍匪—机器学习实战:第四章 训练模型
思谋面试准备
边境的悍匪—机器学习实战:第十五章 使用CNN和RNN处理序列