title: How does a priority queue of pair<int,int> work even without specifying a custom comparator?
body: <p>A <code>std::priority_queue</code> uses a <code>std::vector</code> as the default container (Reference <a href="http://en.cppreference.com/w/cpp/container/priority_queue" rel="nofollow noreferrer">this</a>).  For sorting on the basis of the first element in a <code>std::vector&lt;pair&lt;int, int&gt;&gt;</code>, we need to define our own comparison function (Reference <a href="https://stackoverflow.com/q/18112773/2172854">this</a>).  This is what I understand.</p>
  
  <p>Now, the following code returns the <code>k</code> most frequent elements in a non-empty array, in O(NlogK):</p>
  
  <pre><code>class Solution {
  public:
      vector&lt;int&gt; topKFrequent(vector&lt;int&gt;&amp; nums, int k) {
          if(nums.empty())
              return vector&lt;int&gt;();
  
          unordered_map&lt; int, int &gt; hashMap;
          for(int i=0; i&lt;nums.size(); i++)
              hashMap[nums[i]]++;
  
          priority_queue&lt; pair&lt; int, int &gt;&gt; pq;
          vector&lt; int &gt; result;
          unordered_map&lt; int, int &gt;::iterator it=hashMap.begin();
  
          for(it=hashMap.begin(); it!=hashMap.end(); it++) {
              //the first one is frequency and the second one is the value
              pq.push(make_pair(it-&gt;second, it-&gt;first));
  
              //the peculiar implementation below is because we the code to be O(NlogK)
              if(pq.size()&gt;(hashMap.size()-k)) {
                  result.push_back(pq.top().second);
                  pq.pop();
              }
          }
  
          return result;
      }
  };
  </code></pre>
  
  <p>This code works correctly and gets accepted by the judge - but how?  The <code>std::priority_queue</code>, using a <code>std::vector&lt;pair&lt;int, int&gt;&gt;</code> as its underlying container must contain a custom comparison function so that it sorts correctly.  So, how does it work?</p>