当前位置:网站首页>关于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;
}
边栏推荐
- 二叉树(一):深度优先遍历与广度优先遍历
- 思谋面试准备
- 新导则下 防洪评价报告编制方法及洪水建模(HEC-RAS)
- 抽象工厂模式(Swift 实现)
- Knowledge distillation method of target detection
- Jdbc & Mysql timeout分析
- 【零基础搞定C语言——导航汇总篇】
- 基于全球模式比较计划CMIP6与区域气候-化学耦合模式 WRF-Chem 的未来大气污染变化模拟
- Biome-BGC 生态系统模型与应用
- UAV ecological environment monitoring, image processing and GIS data analysis
猜你喜欢
边境的悍匪—机器学习实战:第七章 集成学习和随机森林
protobuf编码及网络通信应用(一)
Function functional interface and application
Redis 发布/订阅
Target detection, object classification and semantic segmentation of UAV remote sensing images based on PyTorch deep learning
边境的悍匪—机器学习实战:第一章 机器学习的基础知识
海量遥感数据处理与GEE云计算技术应用【基础、进阶】
九、Kotlin基础学习:1、Companion的扩展方法和扩展属性;2、一般类的扩展方法和扩展属性;3、委托;
QT串口动态实时显示大量数据波形曲线(四)========“界面的美化与处理”
常用损失函数(一):Focal Loss
随机推荐
基于遥感解译与GIS技术环境影响评价图件制作(最新导则)
卷积神经网络(CNN)之卷积操作、池化操作、激活函数
GraphQL(一)基础介绍及应用示例
第一个WebAssembly程序
Generalized Focal Loss paper reading notes
边境的悍匪—机器学习实战:第四章 训练模型
八、Kotlin基础学习:1、数据类;2、单例;3、伴生对象;4、密封类;
遥感、GIS和GPS技术在水文、气象、灾害、生态、环境及卫生等应用
Flood Control Assessment Report Compilation Method and Flood Modelling under the New Guidelines (HEC-RAS)
对于国内数据交换平台的分析
什么是过拟合、欠拟合现象以及如何缓解?
基于OpenCV的双目重建
Pytorch(一):动态图机制以及框架结构
Mysql 客户端常见异常分析
Shardingsphere depots table and configuration example
R - GIS: how to use R language implementation of GIS geospatial analysis and model prediction
边境的悍匪—机器学习实战:第八章 降维
Arthas 命令解析(jvm/thread/stack/heapdump)
Function functional interface and application
R language application in the field of ecological environment