0

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);
2
Contributors
1
Reply
3
Views
9 Years
Discussion Span
Last Post by Ancient Dragon
0

any particular reason to use a hash? A simple linked list of structures would do the job. When done reading just sort the list by frequency and you're done.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.