make_heap: rearrange elements in a range such that they form a heap
comparator is a boolean function optional
if v is a vector then
std::make_heap (v.begin(),v.end());v.front() will give you maximum [default is maxheap without comparator]
You can pass the comparator function to each operation to maintain the heap property.
get the element by v.front()
Now pop the element using
pop_heap (v.begin(),v.end()); // can also pass comparator here
[first,last)in such a way that the part considered a heap is shortened by one: The element with the highest value is moved to
(last-1)(which now is out of the heap), the other elements are reorganized in such a way that the range
[first,last-1)preserves the properties of a heap.
pop_heap (v.begin(),v.end()); v.pop_back(); std::cout << "max heap after pop : " << v.front() << '\n';
Given a heap in the range
[first,last-1), this function extends the range considered a heap to
[first,last) by placing the value in
(last-1) into its corresponding location within it.
v.push_back(99); std::push_heap (v.begin(),v.end()); std::cout << "max heap after push: " << v.front() << '\n';