STL—— priority_queue 的重载

<  的重载,按照 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 等效,为升序

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

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

猜你喜欢

转载自www.cnblogs.com/asdfknjhu/p/12596117.html
今日推荐