Search
 
SCRIPT & CODE EXAMPLE
 

CPP

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 << '	' << g.top();
        g.pop();
    }
    cout << '
';
}
 
// 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 << "
gquiz.size() : " << gquiz.size();
    cout << "
gquiz.top() : " << gquiz.top();
 
    cout << "
gquiz.pop() : ";
    gquiz.pop();
    showpq(gquiz);
 
    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ vector of class objects 
Cpp :: Setting a number of decimals on a float on C++ 
Cpp :: vector to string cpp 
Cpp :: implementing split function in c++ 
Cpp :: c++ int length 
Cpp :: sort array c++ 
Cpp :: c++ map insert 
Cpp :: how to find something in a string in c++ 
Cpp :: c elif 
Cpp :: cpp while 
Cpp :: convert int to string in c++ 
Cpp :: sort vector from largest to smallest 
Cpp :: life the universe and everything solution c++ 
Cpp :: cpp lambda function 
Cpp :: cpp vector 
Cpp :: c++ convert const char* to int 
Cpp :: convert char to int c++ 
Cpp :: map in c 
Cpp :: reverse an array in c++ stl 
Cpp :: inheritance example in C plus plus 
Cpp :: convert std vector to array 
Cpp :: oop in cpp 
Cpp :: how to copy vector to another vector in c++ 
Cpp :: create new node in tree 
Cpp :: c++ multiply char 
Cpp :: what is the default include path in ubuntu c++ 
Cpp :: stoi in c++ 
Cpp :: c++ online compiler 
Cpp :: C++ program to print all possible substrings of a given string 
Cpp :: time complexity 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =