Horje
priority queue smallest first Code Example
priority queue smallest first
// C++ program to demonstrate min heap for priority queue
#include <iostream>
#include <queue>
using namespace std;
 
void showpq(
    priority_queue<int, vector<int>, greater<int> > gq)
{
    priority_queue<int, vector<int>, greater<int> > g = gq;
    while (!g.empty()) {
        cout << '\t' << g.top();
        g.pop();
    }
    cout << '\n';
}
 
// Driver Code
int main()
{
    priority_queue<int, vector<int>, greater<int> > gquiz;
    gquiz.push(10);
    gquiz.push(30);
    gquiz.push(20);
    gquiz.push(5);
    gquiz.push(1);
 
    cout << "The priority queue gquiz is : ";
    showpq(gquiz);
 
    cout << "\ngquiz.size() : " << gquiz.size();
    cout << "\ngquiz.top() : " << gquiz.top();
 
    cout << "\ngquiz.pop() : ";
    gquiz.pop();
    showpq(gquiz);
 
    return 0;
}




Cpp

Related
how to format decimal palces in c++ Code Example how to format decimal palces in c++ Code Example
if argv == string Code Example if argv == string Code Example
input n space separated integers in c++ Code Example input n space separated integers in c++ Code Example
how to download c++ portable compiler Code Example how to download c++ portable compiler Code Example
matplotlib hide numbers on axis Code Example matplotlib hide numbers on axis Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
12