pop_heap() in C++ STL

The C++ Standard Library consists of the header, <algorithm> which defines a collection of functions (principally designed to deal with a range of elements). pop_heap() is a method in the STL that is used to delete an element from a heap. The size of the heap effectively decreases by one.


pop_heap( iterator_begin, iterator_end, comparator ); //comparator is optional

Parameters: The pop_heap() method accepts 3 parameters

  • iterator_begin: Iterator to the initial position of heap
  • iterator_end: Iterator to the final position of heap ( Note: the range is [iterator_begin,iterator_end) )
  • comparator: Binary function that accepts two elements in the range as arguments, and returns a value convertible to bool.

Return value: none

Example of pop_heap() method


using namespace std;

int main()
    vector<int> v;

    make_heap(v.begin(), v.end());
    cout<<"Initial heap: "<<v.front()<<endl; //max val

    pop_heap(v.begin(), v.end());
    cout<<"New heap: "<<v.front()<<endl; //max val



Initial heap: 8
New heap: 7

This article is written by

Please comment below, if you have any doubts or find any error in the above article.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top
[gravityforms id="5" description="false" titla="false" ajax="true"]