priority queue of pairs of pair c++ code example

Example 1: priority queue c++ type of pairs

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pi;
// main program
int main() {
   priority_queue<pi, vector<pi>, greater<pi> > pq;
   pq.push(make_pair(10, 200));
   pq.push(make_pair(20, 100));
   pq.push(make_pair(15, 400));
   pair<int, int> top = pq.top();
   cout << top.first << " " << top.second;
   return 0;
}

Example 2: priority queue c++ type of pairs

#include <bits/stdc++.h>
using namespace std;
// main program
int main() {
   priority_queue<pair<int, int> > priorityq;
   priorityq.push(make_pair(18, 200));
   priorityq.push(make_pair(29, 100));
   priorityq.push(make_pair(11, 400));
   pair<int, int> top = priorityq.top();
   cout << top.first << " " << top.second;
   return 0;
}

Tags:

Cpp Example