STL Priority Queue of C Plus Plus Programming Language

STL Priority Queue of C Plus Plus Programming Language

Instructor-svgAl-Mamun Sarkar
Apr 03 , 2020

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

 

  • Share On:
  • fb
  • twitter
  • pinterest
  • instagram