So I'm writing a program in C that reads in a bunch of words from an unspecified number of files and I'm to print out the top N words in the file. I'm using a hash to store them in, where each bucket is a linked list. The lists are sorted by alphabetical order, and every Node has a word and count variable (obvioiusly I only store unique words, repeats increment the count). I have the linked list, the hash, and the reading all working, but what I can't figure out, is an easy way to get the words with the highest counts out of the hash efficiently and print them out.
I keep track of the total number of unique words. Unless I make another array to the size of N, and keep checking in there every time I go through a Node in the hash to see if it's count is bigger than anyone in there, but that seems like way too much trouble.
My hash is basically
Node** hash = (Node**)malloc(sizeof(Node*)*HASHSIZE);