Arafat Hasan
Arafat Hasan

Reputation: 3177

Why is a container parameter used in a priority queue for overloading?

std::priority_queue< int, std::vector<int>, std::greater<int> > pq;

Why is the vector parameter used?

Upvotes: 0

Views: 119

Answers (1)

Davide Spataro
Davide Spataro

Reputation: 7482

  • The priority queue implementation can use different types of containers to build the underlining data structure. You can specify which one you like the most using that template parameter.

  • Quoting from 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.

Btw, vector is the default one.

Upvotes: 2

Related Questions