title: Top 10 Frequencies in a Hash Table with Linked Lists
body: <p>The code below will print me the highest frequency it can find in my hash table (of which is a bunch of linked lists) 10 times. I need my code to print the top 10 frequencies in my hash table. I do not know how to do this (code examples would be great, plain english logic/pseudocode is just as great).</p>
  
  <ol>
  <li>I create a temporary hashing list called 'tmp' which is pointing to my hash table 'hashtable'</li>
  <li>A while loop then goes through the list and looks for the highest frequency, which is an int 'tmp->freq'</li>
  <li>The loop will continue this process of duplicating the highest frequency it finds with the variable 'topfreq' until it reaches the end of the linked lists on the the hash table.</li>
  </ol>
  
  <p>My 'node' is a struct comprising of the variables 'freq' (int) and 'word' (128 char). When the loop has nothing else to search for it prints these two values on screen.</p>
  
  <p>The problem is, I can't wrap my head around figuring out how to find the next lowest number from the number I've just found (and this can include another node with the same freq value, so I have to check that the word is not the same too).</p>
  
  <pre><code>void toptenwords()
  {
      int topfreq = 0;
      int minfreq = 0;
      char topword[SIZEOFWORD];
  
      for(int p = 0; p &lt; 10; p++) // We need the top 10 frequencies... so we do this 10 times
      {
          for(int m = 0; m &lt; HASHTABLESIZE; m++) // Go through the entire hast table
          {
              node* tmp;
              tmp = hashtable[m];
  
              while(tmp != NULL) // Walk through the entire linked list
              {
                  if(tmp-&gt;freq &gt; topfreq) // If the freqency on hand is larger that the one found, store...
                  {
                      topfreq = tmp-&gt;freq;
                      strcpy(topword, tmp-&gt;word);
                  }
                  tmp = tmp-&gt;next;
              }
          }
          cout &lt;&lt; topfreq &lt;&lt; "\t" &lt;&lt; topword &lt;&lt; endl;
      }
  }
  </code></pre>
  
  <p>Any and all help would be GREATLY appreciated :)</p>