#include <algorithm>
#include <iostream>
#include <vector>
#include <boost/foreach.hpp>
int main ()
{
std::vector<int> v;
v.push_back(1);
v.push_back(2);
v.push_back(3);
v.push_back(4);
v.push_back(5);
std::cout << "Initial std::vector: ";
BOOST_FOREACH(int i, v) std::cout << i << ' ';
std::make_heap(v.begin(),v.end());
std::cout << "\nstd::vector after std::make_heap: ";
BOOST_FOREACH(int i, v) std::cout << i << ' ';
v.push_back(10);
std::push_heap(v.begin(),v.end());
std::cout << "\nstd::vector after std::push_heap of 10: ";
BOOST_FOREACH(int i, v) std::cout << i << ' ';
std::pop_heap(v.begin(),v.end());
v.pop_back();
std::cout << "\nstd::vector after std::pop_heap (which removes the heighest value): ";
BOOST_FOREACH(int i, v) std::cout << i << ' ';
std::sort_heap(v.begin(),v.end());
std::cout << "\nstd::vector after std::sort_heap: ";
BOOST_FOREACH(int i, v) std::cout << i << ' ';
}
|