Answers for "how to declare priority queue c++"

C++
1

priority queue in c++

//Shubh'grepper
// Implementation of priority_queue in c++

//queue with elements in decreasing order
priority_queue<int> pq;

// queue with elements in increasing order  using compare function inside declaration
priority_queue <int, vector<int>, greater<int> > pq;

//priority_queue of type pair<int, int>
#define pp pair<int, int>
priority_queue <pp, vector<pp>, greater<pp> > pq;
Posted by: Guest on November-26-2020
1

priority queue stl

#include<iostream>
#include<queue>
#include<algorithm>

using namespace std;

int main()
{
    priority_queue<int>pq;
    int n=5;
    while(n--)
    {
        int val;
        cout<<"enter the value you want to insert:"<<endl;
        cin>>val;
        pq.push(val);
    }
    priority_queue<int>p;
    p.push(100);
    p.push(1000);
    p.push(3000);
    p.push(5000);
    pq.swap(p);
    while(!pq.empty())
    {
        cout<<pq.top()<<" ";
        pq.pop();
    }
    return 0;
}
Posted by: Guest on June-06-2021

Code answers related to "how to declare priority queue c++"

Browse Popular Code Answers by Language