在结构体中
struct Node
{
int cost;//cost越小排前面
int test;
};
我想在priority_queue中使用结构体,然后按int cost的大小为优先级,请问如何使用设置?
优先队列 排列结构体
答案:1 悬赏:70
解决时间 2021-02-04 06:14
- 提问者网友:一人心
- 2021-02-04 00:39
最佳答案
- 二级知识专家网友:悲观垃圾
- 2021-02-04 01:18
重载<运算符
bool operator<( Node a, Node b ){
return a.cost<b.cost;
}
用的时候:
priority_queue<Node> pq;
就可以了
bool operator<( Node a, Node b ){
return a.cost<b.cost;
}
用的时候:
priority_queue<Node> pq;
就可以了
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯
• 手机登qq时,显示手机磁盘不足,清理后重新登 |
• 刺客的套装怎么选啊? |