C++ 优先级队列第二个参数:容器对象
我知道priority_queue的第二个参数是一个容器(默认情况下,它是一个C++ 优先级队列第二个参数:容器对象,c++,priority-queue,C++,Priority Queue,我知道priority_queue的第二个参数是一个容器(默认情况下,它是一个向量)。但是如果我想使用队列或列表作为底层容器,该怎么办 struct compare { bool operator()(int&a,int&b) { return a > b; } }; int main(int argc, char** argv) { std::priority_queue<int, queue<int> , co
向量
)。但是如果我想使用队列
或列表
作为底层容器,该怎么办
struct compare {
bool operator()(int&a,int&b) {
return a > b;
}
};
int main(int argc, char** argv) {
std::priority_queue<int, queue<int> , compare >pq();
return 0;
}
结构比较{
布尔运算符()(int&a,int&b){
返回a>b;
}
};
int main(int argc,字符**argv){
std::priority_queuepq();
返回0;
}
当我使用pq.push()
时,它不起作用所以必须
priority\u queue
使用vector
作为容器吗?或者我如何使用队列来代替
我非常感谢你的帮助。Thanx很多。由此:
容器-用于存储元素的基础容器的类型。这个
容器必须满足的要求,其迭代器必须满足RandomAccessIterator的要求。
此外,它必须提供以下功能与通常的
语义:
- 前()
- 推回
- 回来
队列不是容器。它也是一个适配器,默认情况下使用deque。