title: Min Heap using STL Priority Queue explanation
body: <p>I am fairly new to C++ and I was trying to implement a Min Heap using Priority Queue STL in C++. I looked around the web and chanced upon a code, the link to which I have added at the bottom.</p>
  
  <p>I understand how vectors work and I also understand what a functor is but I can't understand how 'return i>j' plays a part in arranging the elements from minimum to maximum.</p>
  
  <p>I will post the code here.</p>
  
  <pre><code>#include &lt;queue&gt;
  #include &lt;iostream&gt;
  
  using namespace std;
  
  struct comparator {
       bool operator()(int i, int j) {
       return i &gt; j;
      }
  };
  
  int main(int argc, char const *argv[])
  {
       priority_queue&lt;int, std::vector&lt;int&gt;, comparator&gt; minHeap;
  
      minHeap.push(10);
      minHeap.push(5);
      minHeap.push(12);
      minHeap.push(3);
      minHeap.push(3);
      minHeap.push(4);
  
      while (!minHeap.empty()) {
      cout &lt;&lt; minHeap.top() &lt;&lt; " ";
      minHeap.pop();
      }
      return 0;
  }
  </code></pre>
  
  <p>Could someone please trace the program's execution? I have been trying to understand how this program works for the past couple of hours with no luck.</p>
  
  <p>I got the code from <a href="https://codeconnect.wordpress.com/2013/09/05/max-min-heap-using-c-stl/" rel="nofollow">here</a></p>