//
//  main.cpp
//  Max Heap
//
//  Created by Himanshu on 02/10/21.
//


#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;

int main () {
    
    vector<int> maxHeap = {30, 100, 25, 40};
    make_heap(maxHeap.begin(), maxHeap.end());
    
    cout<<"Insert H(x) {20, 70}"<<endl;
    maxHeap.push_back(20);
    push_heap(maxHeap.begin(), maxHeap.end());
    maxHeap.push_back(70);
    push_heap(maxHeap.begin(), maxHeap.end());

    cout<<"Maximum Element (H)"<<endl;
    cout<<maxHeap.front()<<endl;
    
    cout<<"Maximum Element (H) after Extract-Max (H)"<<endl;
    pop_heap(maxHeap.begin(), maxHeap.end());
    maxHeap.pop_back();
    cout<<maxHeap.front()<<endl;
    
    cout <<"Extracting out elements..."<<endl;
    while (!maxHeap.empty()) {
        cout<< maxHeap.front()<<" ";
        pop_heap(maxHeap.begin(), maxHeap.end());
        maxHeap.pop_back();
    }
    cout<<endl;
    
    if (maxHeap.empty()) {
        cout<<"Heap is empty"<<endl;
    } else {
        cout<<"Heap is not empty"<<endl;
    }
    
  return 0;
}
