为什么在优先级队列中使用容器参数进行重载?
Why is a container parameter used in a priority queue for overloading?
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
是默认值。
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
是默认值。