首页 > 其他 > 详细

STL—— priority_queue 的重载

时间:2020-03-30 09:58:26      阅读:75      评论:0      收藏:0      [点我收藏+]

<  的重载,按照 dis 的大小升序排序

1,

typedef struct node    // 队列里要放的应该是 点的 id 和 distance ,而不是一条边
{
    int id;    
    int dis;   
    node() {}
    node(int  a, int b) :id(a), dis(b) {}
    bool operator <(const node &a)const  // < 的重载
    {
        return a.dis < dis;
    }
}st;
priority_queue <st>q;

2,

typedef struct node    // 队列里要放的应该是 点的 id 和 distance ,而不是一条边
{
    int id;
    int dis;
    node() {}
    node(int  a, int b) :id(a), dis(b) {}
    friend bool operator <(const node &a,const node &b)  // < 的重载
    {
        return a.dis > b.dis;
    }
}st;
priority_queue <st>q;

1,2 等效,为升序

 

========= ======== ======== ======= ====== ==== === == =

连自己喜欢什么都不敢尝试的话,终究连自己都看不起自己 

 

STL—— priority_queue 的重载

原文:https://www.cnblogs.com/asdfknjhu/p/12596117.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!