Answers for "top priority queue in 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
0

C++ accessing in priority queue

/* Program to access an element of highest priority */
 
#include<iostream>
#include<queue>     //Header-file for queue
using namespace std;
 
 
int main()
{
priority_queue<int> p1;
p1.push(35);    
p1.push(40);
p1.push(95);
p1.push(25);
  
cout<<p1.top();      //fetch element of highest
priority(maximum element) i.e 95
}
Posted by: Guest on July-28-2021

Code answers related to "top priority queue in c++"

Browse Popular Code Answers by Language