Here can be the one more example on the push_heap() function of the C++ language and the following program can help's you to learn the push_heap() function :
Code:
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <numeric>
template <class S>
inline void PRNTELMNTS (const S& cl, const char* otcstr="")
{
typename S::const_iterator pos;
std::cout << otcstr;
for (p=cl.begin(); p!=cl.end(); ++p)
{
std::cout << *p << ' ';
}
std::cout << std::endl;
}
template <class S>
inline void INSRTELMNTS (S& cl, int fst, int lst)
{
for (int a=fst; a<=lst; ++a)
{
cl.insert(cl.end(),a);
}
}
using namespace std;
int main()
{
vector<int> cl;
INSRTELMNTS(cl,3,7);
INSRTELMNTS(cl,5,9);
INSRTELMNTS(cl,1,4);
PRNTELMNTS (cl, "on entry: ");
cl.push_back (17);
push_heap (cl.begin(), cl.end());
PRNTELMNTS (cl, "after push_heap(): ");
}
OUTPUT :
Code:
on entry: 3 4 5 6 7 5 6 7 8 9 1 2 3 4
after push_heap(): 17 8 9 7 7 5 6 3 6 4 1 2 3 4 5
Bookmarks