Work with heaps: make_heap from vector
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
vector<char> vectorObject;
int i;
for(i = 0; i <20; i+=2)
vectorObject.push_back('A'+i);
cout << "Sequence before building heap:";
for(i = 0; i <vectorObject.size(); i++)
cout << vectorObject[ i ] << " ";
cout << endl;
make_heap(vectorObject.begin(), vectorObject.end());
cout << "Sequence after building heap:";
for(i = 0; i <vectorObject.size(); i++)
cout << vectorObject[ i ] << " ";
cout << endl;
vectorObject.push_back('H');
push_heap(vectorObject.begin(), vectorObject.end());
cout << "Sequence after pushing onto heap:";
for(i = 0; i <vectorObject.size(); i++)
cout << vectorObject[ i ] << " ";
cout << endl;
pop_heap(vectorObject.begin(), vectorObject.end());
cout << "Sequence after poping from heap:";
for(i = 0; i <vectorObject.size(); i++)
cout << vectorObject[ i ] << " ";
cout << endl;
return 0;
}
Related examples in the same category