Which heap structure uses the C ++ STL queue priority?
This question is marked as C ++ (as opposed to asking for specific details for a specific specific compiler), so I checked the standard for any information. In the various sections 23.6.4 we learn that it priority_queue
just behaves like this: if it uses make_heap
, push_heap
and pop_heap
. These functions are then documented (in sections 25.4.6
) as having complexity At most 3 * (last - first) comparisons.
, At most log(last - first) comparisons.
and At most 2 * log(last - first) comparisons.
so on. Thus, certain characteristics of the heap can be specified by these characteristics, but no particular heap is called.
source to share
You can select the container underlying the priority_queue. If not specified, std :: vector is used by default:
template<
class T,
class Container = std::vector<T>,
class Compare = std::less<typename Container::value_type>
> class priority_queue;
Container - The type of base container that will be used to store items. The container must satisfy the SequenceContainer requirements. In addition, it must provide the following functions with the usual semantics: front () push_back () pop_back () standard containers std :: vector and std :: deque satisfy these requirements.
The heap is implemented by functions *_heap
, in a simple way. You can check the code here:
http://www.sgi.com/tech/stl/stl_heap.h
source to share