std::priority_queue< int, std::vector<int>, std::greater<int> > pq;
为什么要使用vector参数?
最佳答案
优先级队列实现可以使用不同类型的容器来构建底层数据结构。您可以使用该模板参数指定您最喜欢哪一个。
引自 here
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.
顺便说一句,vector
是默认的。
关于c++ - 为什么在优先级队列中使用容器参数进行重载?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44995031/