The program that can be mentioned below illustrates you about how to use the pop_heap() function in the C++ language programming :
Code:
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main ()
{
int mit[] = {10,20,30,5,15};
vector<int> w(mit,mit+5);
vector<int>::iterator it;
make_heap (w.begin(),w.end());
cout << "initial max heap : " << w.front() << endl;
pop_heap (w.begin(),w.end()); w.pop_back();
cout << "max heap after pop : " << w.front() << endl;
w.push_back(99); push_heap (w.begin(),w.end());
cout << "max heap after push: " << w.front() << endl;
sort_heap (w.begin(),w.end());
cout << "final sorted range :";
for (unsigned k=0; k<w.size(); k++) cout << " " << w[k];
cout << endl;
return 0;
}
Output:
Code:
initial max heap : 30
max heap after pop : 20
max heap after push: 99
final sorted range : 5 10 15 20 99
Bookmarks