//
// main.cpp
// Priority Queue (Min Heap)
//
// Created by Himanshu on 19/09/21.
//
#include <iostream>
#include <queue>
#include <functional>
using namespace std;
int main () {
priority_queue<int, vector< int>, greater <int> > pq;
cout<<"Insert Q(x) {30, 100, 25, 40}"<<endl;
pq.push(30);
pq.push(100);
pq.push(25);
pq.push(40);
cout<<"Minimum Element (Q)"<<endl;
cout<<pq.top()<<endl;
cout<<"Minimum Element (Q) after Extract-Min (Q)"<<endl;
pq.pop();
cout<<pq.top()<<endl;
cout <<"Extracting out elements..."<<endl;
while (!pq.empty()) {
cout<< pq.top()<<" ";
pq.pop();
}
cout<<endl;
if (pq.empty()) {
cout<<"Priority queue is empty"<<endl;
} else {
cout<<"Priority queue is not empty"<<endl;
}
return 0;
}
Ly8KLy8gIG1haW4uY3BwCi8vICBQcmlvcml0eSBRdWV1ZSAoTWluIEhlYXApCi8vCi8vICBDcmVhdGVkIGJ5IEhpbWFuc2h1IG9uIDE5LzA5LzIxLgovLwoKI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8cXVldWU+CiNpbmNsdWRlIDxmdW5jdGlvbmFsPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4gKCkgewogICAgCiAgICBwcmlvcml0eV9xdWV1ZTxpbnQsIHZlY3RvcjwgaW50PiwgZ3JlYXRlciA8aW50PiA+IHBxOwogICAgCiAgICBjb3V0PDwiSW5zZXJ0IFEoeCkgezMwLCAxMDAsIDI1LCA0MH0iPDxlbmRsOwogICAgcHEucHVzaCgzMCk7CiAgICBwcS5wdXNoKDEwMCk7CiAgICBwcS5wdXNoKDI1KTsKICAgIHBxLnB1c2goNDApOwogICAgCiAgICBjb3V0PDwiTWluaW11bSBFbGVtZW50IChRKSI8PGVuZGw7CiAgICBjb3V0PDxwcS50b3AoKTw8ZW5kbDsKICAgIAogICAgY291dDw8Ik1pbmltdW0gRWxlbWVudCAoUSkgYWZ0ZXIgRXh0cmFjdC1NaW4gKFEpIjw8ZW5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