当前位置:网站首页>关于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;
}
边栏推荐
- 海量遥感数据处理与GEE云计算技术应用【基础、进阶】
- 常用损失函数(二):Dice Loss
- AAcell五号文档室——跨平台文件传输的小室一间一间的
- Redis publish/subscribe
- 1.03 original Acegi security mechanism
- 十六、Kotlin进阶学习:协程详细学习。
- QT串口动态实时显示大量数据波形曲线(五)========“最终完美解决版”
- Function functional interface and application
- mysql delete duplicate data in the table, (retain only one row)
- HSPF 模型应用
猜你喜欢

边境的悍匪—机器学习实战:第十章 Keras人工神经网络简介

CLUE模型构建方法、模型验证及土地利用变化情景预测

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

原型模式(Prototype):Swift 实现

Reasons and solutions for Invalid bound statement (not found)

边境的悍匪—机器学习实战:第七章 集成学习和随机森林

Flink-流/批/OLAP一体得到Flink引擎

Twenty-two, Kotlin advanced learning: simply learn RecyclerView to achieve list display;

Configure MMdetection environment and train

Xcode 建立 UIKit 项目(Hello World)
随机推荐
MATLAB怎么在图像中显示nii文件切片信息?
Flink-stream/batch/OLAP integrated to get Flink engine
为什么会出现梯度爆炸和梯度消失现象?怎么缓解这种现象的发生?
Redis publish/subscribe
边境的悍匪—机器学习实战:第六章 决策树
Receive emails from gmail with pop3
Target detection, object classification and semantic segmentation of UAV remote sensing images based on PyTorch deep learning
R语言 生态环境领域应用
HSPF 模型应用
第一个WebAssembly程序
MySQL 索引的数据结构及类型
【Qingdao Station】High-level application of SWAT model and modeling of areas without data, uncertainty analysis and climate change, improvement of land use surface pollution impact model and case analy
C语言学习经验
原创 Acegi 1.03 安全机制
How does MATLAB display nii file slice information in the image?
边境的悍匪—机器学习实战:第二章 端到端的机器学习项目
Generalized Focal Loss 论文阅读笔记
Shardingsphere depots table and configuration example
QT每周技巧(3)~~~~~~~~~串口添加
Rsync realizes folder or data synchronization between Win systems