title: Unexpected behaviour of Priority_queue size
body: <p>I was writing the code for the problem. <strong>Median of the stream of integers</strong> when I encountered an issue. Note that this issue is not the algorithmic but rather ambiguous behavior of the <code>priority_queue</code> size.</p>
  
  <pre><code>#include &lt;bits/stdc++.h&gt;
  using namespace std;
  priority_queue&lt;double&gt; small;
  priority_queue&lt;double, vector&lt;double&gt;, greater&lt;double&gt; &gt; large;
  void rebalance()
  {
      cout &lt;&lt; "Initial size\n";
      cout &lt;&lt; "small " &lt;&lt; small.size() &lt;&lt; " large " &lt;&lt; large.size() &lt;&lt; endl;
      if (small.size() - large.size()&gt;1)
      {
          large.push(small.top());
          small.pop();
      }
      else if (large.size() - small.size()&gt;1)
      {
          cout &lt;&lt; "Unexpectedly goes here\n";
          cout &lt;&lt; "garbage size difference " &lt;&lt; large.size() - small.size() &lt;&lt; endl;
          small.push(large.top());
          large.pop();
      }
  }
  void addNum(int num) {
      if (small.size() == 0 || num&lt;small.top())
      {
          small.push(num);
      }
      else
      {
          large.push(num);
      }
      rebalance();
  }
  
  double findMedian() {
      if (small.size() == large.size())
      {
          double ans = (small.top() + large.top()) / 2.0;
          return ans;
      }
      else if (small.size()&gt;large.size())
      {
          return (double)small.top();
      }
      else
      {
          return (double)large.top();
      }
  }
  int main()
  {
      std::ios_base::sync_with_stdio(false);
      int num = 5;
      addNum(num);
      cout &lt;&lt; findMedian() &lt;&lt; endl;
      return 0;
  }
  </code></pre>
  
  <p>The output for this code is</p>
  
  <pre><code>   Initial size
     small 1 large 0
     Unexpectedly goes here
     garbage size difference 18446744073709551615
     fish: “./a.out” terminated by signal SIGSEGV (Address boundary error)
  </code></pre>
  
  <p>In the <code>rebalance</code> function the initial size of <code>small</code> is <code>1</code> and large is <code>0</code> which suggest that the loop should neither enter the if condition nor the else if condition but the loop enters the <strong>else if</strong> condition with a garbage value in size.why does this happen? Moreover I tried saving the small and large size in an integer variable and then comparing them in conditionals,which lead to acceptance of the code. Hence the algorithm handles the correctness.</p>
  
  <p>What leads to this garbage value?</p>