【知识点】
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