title: sort an unordered_map using sort()
body: <p>I am trying to sort an <code>unordered_map</code> using <code>sort()</code> function but I keep getting a compiler error. Can anyone help?</p>
  
  <pre><code>bool comp(pair&lt;char,int&gt; a, pair&lt;char,int&gt; b) {
      return a.second &lt; b.second;
  }
  
  void rearrangeKDist(char str[], int d) {
      int n = strlen(str);
      unordered_map&lt;char, int&gt; table;
      for (int i=0; i&lt;n; i++) {
          unordered_map&lt;char, int&gt;::iterator it = table.find(str[i]);   
          if (it == table.end()) {
              table.insert(make_pair(str[i], 1));
          } else {
              it-&gt;second = it-&gt;second+1;
          }
      }
      for (unordered_map&lt;char, int&gt;::iterator it=table.begin(); it!=table.end(); it++)
          cout&lt;&lt;it-&gt;first&lt;&lt;" "&lt;&lt;it-&gt;second&lt;&lt;endl;
      sort(table.begin(), table.end(), comp);
      for (unordered_map&lt;char, int&gt;::iterator it=table.begin(); it!=table.end(); it++)
          cout&lt;&lt;it-&gt;first&lt;&lt;" "&lt;&lt;it-&gt;second&lt;&lt;endl;
  
  }
  </code></pre>