C++ STL - Reverse Priority Queue Last Updated : 02 Nov, 2022 Comments Improve Suggest changes Like Article Like Report 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. Syntax: priority_queue <data_type, vector<data_type>, greater<data_type>> variable_name; Example: C++ // C++ program to demonstrate priority // queue in reverse order #include <iostream> #include <queue> using namespace std; int main() { // Initialising the priority queue priority_queue<int, vector<int>, greater<int> > pq; // Inserting values in priority queue pq.push(10); pq.push(30); pq.push(20); pq.push(15); pq.push(25); cout << "The priority queue in reverse order is : "; // Printing all elements in priority queue while(!pq.empty()) { cout<<pq.top()<<" "; pq.pop(); } return 0; } OutputThe priority queue in reverse order is : 10 15 20 25 30 Example: C++ // C++ program to demonstrate priority queue in reverse order #include <bits/stdc++.h> using namespace std; int main() { // Initialising the priority queue priority_queue<string, vector<string>, greater<string> > pq; // Inserting values in priority queue pq.push("physics"); pq.push("chemistry"); pq.push("maths"); pq.push("socialstudies"); pq.push("biology"); cout << "The priority queue in reverse order is : "; // Printing all elements in priority queue while(!pq.empty()) { cout<<pq.top()<<" "; pq.pop(); } return 0; } OutputThe 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? Comment More infoAdvertise with us Next Article C++ STL - Reverse Priority Queue P pushpeshrajdx01 Follow Improve Article Tags : Technical Scripter C++ Technical Scripter 2022 STL cpp-queue +1 More Practice Tags : CPPSTL Similar Reads Priority Queue in C++ STL In C++, priority queue is a type of queue in which there is some priority assigned to the elements. According to this priority, elements are removed from the queue. By default, the value of the element being inserted is considered as priority. Higher its value, higher its priority. But this can be c 6 min read priority_queue::top() in C++ STL Priority queues are a type of container adaptors, specifically designed such that the first element of the queue is either the greatest or the smallest of all elements in the queue. In general, elements are arranged according to some priority. However in C++ STL, the top element is the greatest elem 3 min read priority_queue::swap() in C++ STL Priority queues are a type of container adaptors, specifically designed such that the first element of the queue is either the greatest or the smallest of all elements in the queue. However, in C++ STL (by default) the largest element is at the top. We can also create a priority queue having the sma 3 min read priority_queue emplace() in C++ STL Priority queues are a type of container adaptors, specifically designed such that the first element of the queue is either the greatest or the smallest of all elements in the queue. However, in C++ STL (by default) the largest element is at the top. We can also create a priority queue having the sma 4 min read priority_queue value_type in C++ STL The priority_queue :: value_type method is a built-in function in C++ STL which represents the type of object stored as an element in a priority_queue. It acts as a synonym for the template parameter. Time complexity: O(1)Syntax: priority_queue::value_type variable_name It has no parameters and no r 2 min read Like