priority_queue元素为结构体时重载 operator< 的两种等价代码

【知识点】
STL
priority_queue 具有“自动排序”的强大功能。其默认使用 operator< 的比较方式进行排序。 但是,对于自定义类型(如结构体、联合体、枚举等),则必须重载 operator< 比较方式。
详见:https://blog.csdn.net/hnjzsyjyj/article/details/124521165

例如,重载 operator< 的两种等价代码如下所示。

struct Node {
    int pr,index;
};
bool operator<(Node a,Node b) {
    return a.pr>b.pr;
}
struct Node {
    int pr,index;
    bool operator<(const Node &b) const {
        return pr>b.pr;
    }
};


【参考文献】
https://blog.csdn.net/hnjzsyjyj/article/details/124521165
https://blog.csdn.net/hnjzsyjyj/article/details/120184972
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值