C++ STL – Reverse Priority Queue
A priority Queue is an abstract data type that resembles a queue, and each element has a corresponding priority value. Priority queues are built on the top of the max heap and use an array or vector as an internal structure.
In C++ STL, by default, the first element of the queue is the greatest of all elements in the queue and elements are in nonincreasing order. But however, we can make a priority queue having the smallest element at the top as min-heap with the help of greater<data_type> in C++ STL.
priority_queue <data_type, vector<data_type>, greater<data_type>> variable_name;
The priority queue in reverse order is : 10 15 20 25 30
The priority queue in reverse order is : biology chemistry maths physics socialstudies
For more information, refer to the article – How to implement Min Heap using STL?
My Personal Notes arrow_drop_up
Please Login to comment...