title: Min Binary Heap issue
body: <p>i need help with this minheap code:</p>
  
  <pre><code>#include &lt; vector&gt;
  
  using namespace std;
  
  class heap {
  
      vector &lt;int&gt; v;
  
      public:
  
          int hSize()
          {
              return v.size();
          }
  
          int rsize()
          {
              return  hSize() - 1;
          }    
  
          int parent(int i) 
          {
              return (i - 1) / 2;
          }
  
          int left(int i)
          {
              return i * 2 + 1;
          }
  
          int right(int i)
          {
              return i * 2 + 2;
          }
  
          void swap(int i, int j)
          {
              int temp = v[j];
              v[j] = v[i];
              v[i] = temp;
          }
  
          void push(int e)
          {
  
              v.push_back(e);
              int id = rsize(); 
  
              if (hSize() &gt; 1)
                  while (v[parent(id)] &gt; v[id]) {               
                      swap(parent(id), id);
                      id = parent(id);
                  }
          }
  
          int pop ()
          {
  
            int f = 0;  
            int p = v[0];
  
            v[0] = v[rsize()];
  
            if (hSize() &gt; 1) {
                while (v[left(f)] &lt; v[f] || v[right(f)] &lt; v[f]) {
                      if (v[left(f)] &lt; v[f] &amp;&amp; v[right(f)] &lt; v[f]) {
                          if (v[left(f)] &lt; v[right(f)]) {
                              swap(left(f), f);
                              f = left(f);
                      }
                      else { 
                              swap(right(f), f);
                              f = right(f);
                      }
                  }
  
                  else {
                      if (v[left(f)] &lt; v[f]){
                           swap(left(f), f);
                           f = left(f);
                      }
                      else {
                           swap(right(f), f);
                           f = right(f);
                          }
                      }
                  } 
            }
            else { }
  
            v.resize(rsize());
            return p;
          }
  
          void show()
          {
              if (hSize() &gt; 0) {
                  cout &lt;&lt; "Heap content: ";
                  for (int i = 0; i &lt; hSize(); i++) cout &lt;&lt; v[i] &lt;&lt; " ";
              }
              else cout &lt;&lt; "\nHeap successfully emptied!";  
              cout &lt;&lt; "\n";          
          }
  
          bool Empty()
          {
              return v.empty();
          }
  
          ~heap()
          {
              v.clear();
          }
  
      };         
  </code></pre>
  
  <p>Well, the code does almost everything right, except when it pops the last element on the screen it prints a random number. What's your opinion?</p>
  
  <p>Thanks!</p>