min heap pair c++ code example
Example 1: min heap in c++
priority_queue <int, vector<int>, greater<int>> minHeap;
Example 2: priority queue c++ type of pairs
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pi;
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 3: how to store pair in min heap in c++
typedef pair<int, int> pi;
priority_queue<pi, vector<pi>, greater<pi> > pq;