gpt4 book ai didi

c++ - priority_queue 第二个参数 :Container object

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:15:40 24 4
gpt4 key购买 nike

我知道 priority_queue 的第二个参数是一个容器(默认情况下它是一个 vector)。但是,如果我想使用 queuelist 作为底层容器怎么办?

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;
}

当我使用 pq.push() 时它不起作用。
那么priority_queue一定要用vector作为容器吗?或者我该如何改用队列?

非常感谢您的帮助。非常感谢。

最佳答案

从这里reference :

Container - The type of the underlying container to use to store the elements. The container must satisfy the requirements of SequenceContainer and its iterators must satisfy the requirements of RandomAccessIterator. Additionally, it must provide the following functions with the usual semantics:

  • front()
  • push_back()
  • pop_back()

The standard containers std::vector and std::deque satisfy these requirements.

关于c++ - priority_queue 第二个参数 :Container object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33955220/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com