Top word frequency counter help

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2006
Posts: 30
Reputation: Acquire is an unknown quantity at this point 
Solved Threads: 0
Acquire Acquire is offline Offline
Light Poster

Top word frequency counter help

 
0
  #1
Apr 20th, 2008
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
  1. Node** hash = (Node**)malloc(sizeof(Node*)*HASHSIZE);
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,661
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1500
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Top word frequency counter help

 
0
  #2
Apr 20th, 2008
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.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C Forum


Views: 949 | Replies: 1
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC