This article is about the push_heap() algorithm function with std::vector container. It is
an STL algorithm in <algorithm> header file. It places a new element in the last-1 position
when a heap of ranhe [first, last-1) is given. After a heap is created then the push_heap
preserves the characteristics of the heap.
push_heap() can take two forms:
(1) template <class RandomAccessIterator>
void push_heap (RandomAccessIterator first, RandomAccessIterator last);
(2) template <class RandomAccessIterator, class Compare>
void push_heap (RandomAccessIterator first, RandomAccessIterator last,
In 1st is the default case and the 2nd one is the custom case. It uses comp function for
the comparison. comp is a binary function which accepts 2 values and returns a bool value
which indicates whether the first element is less than the second or not. If the heap is not
empty or one element heap then this comp function is used.
Here the first definition is discussed.
Marks of few students are stored in a database. Enter new marks of some students and
dispaly the highest marks.
using namespace std;
int i, n, m;
// marks of the students
cout<<"Enter the number of students whose new marks is to be entered: ";
cout<<"Enter the marks: ";
cout<<"Highest Marks: "<<marks.front()<<endl;