C++在else/if中声明一个优先级队列
C++ declare a priority queue in an else/if?
我有两个不同的优先级队列,它们使用不同的比较器。我想要一个带有布尔值的if/else来确定哪个p.q将被设置为变量(例如,"pq");
例如,我有
priority_queue<test, vector<test>, CompareTest1> pq;
我该如何将其放在if/else中?因此,如果布尔值被标记,pq将被设置为。。。
priority_queue<test, vector<test>, CompareTest2> pq;
使用不同的比较器。谢谢
这是无法完成的,因为如果您给定不同的模板参数,则两个模板的类型不同。我的建议是传递一个比较函子,它有一个布尔值,由if语句中的内容决定。例如:
struct compare {
bool b;
//set this instead of the if statement and allow the function to do something different
operator () (const test & lhs, const test & rhs) {
}
};
优先级队列的结构不允许您寻找什么——元素在优先级队列中根据其比较器进行排序。使用不同的比较器创建优先级队列相当于创建一个全新的优先级队列。
相关文章:
- 在一个读写器队列中,我可以用volatile替换原子吗
- 我已经做了一个程序来使用队列链C++表显示学生姓名和身高,现在我想以我不知道如何显示的顺序显示它
- 为什么我们需要在优先级队列声明中添加一个向量作为参数?
- 我们可以在队列前面以 O(1) 时间复杂度排队一个元素吗?
- CSActiveMQ CPP 生产者 - 一个会话可以使用多个队列吗?
- 一个好的线程池队列大小
- 我有一个问题,创建了C 中阻塞队列的向量
- 哪个架构更好?多个 SPSC 队列或一个 MPSC 队列
- 有没有机会触发一个不知道拥有队列的kevent?还有其他选择吗?
- 我正在声明一个自定义优先级队列,包括 pair<pair<int,int>int >,如何清除它?
- 如何读取STD ::队列与另一个线程共享
- 另一个线程安全队列实现
- 如何创建一个将队列作为数据成员的类,该成员在 c++ 中存储另一个类的实例
- 正在提取优先级队列的最后一个元素
- 我可以放一个lambdas的无锁队列吗?
- 在队列上的最后一个操作循环中的错误
- 将队列实例的前面复制到另一个队列实例的后面
- 一个队列的Mat图像元素:如何
- 为什么一个队列的大小会小于一个小数字
- 返回一个队列的函数