STL Priority Queue of C Plus Plus Programming Language

Author: Al-mamun Sarkar Date: 2020-04-03 19:50:41

STL Priority Queue of C Plus Plus Programming Language. The following code shows how to use priority queue in C++ programming language.

 

Code:

#include <iostream>
#include <queue>
using namespace std;

int main()
{
    priority_queue < int > q;

    q.push(485);
    q.push(4554);
    q.push(57);
    q.push(7896);

    cout << "Size of queue is : " << q.size() << endl;

    while (!q.empty()) {
        cout << q.top() << endl;
        q.pop();
    }

    return 0;
}

 

Output:

Size of queue is : 4
7896
4554
485
57