Last Updated: February 25, 2016
·
1.088K
· pctroll

Always read the documentation carefully

I happened to crash into a wall when didn't read the documentation carefully for using pushheap and popheap from the C++ STL library.

In a nutshell

vector<T> myHeap;

myHeap.push_back(T);
push_heap(myHeap.begin(), myHeap.end(), CompareFunction);

// It doesn't actually pop the heap, but put the element at the end
// of the array
push_heap(myHeap.begin(), myHeap.end(), CompareFunction);
// It actually pops the element
myHeap.pop_back();