Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Word Frequency Count  RSS feed

 
Kirstie Fran
Ranch Hand
Posts: 33
Android Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have some code that creates a binary search tree with the words from a .txt file. I have a tree created already called searchTree, I want to count the frequency of each word placed in the Tree and am creating a new tree as i go along.
The idea is that, if the word is not already in the tree, add it and set the count to 1, else dont add it again, just increase the count.


My output looks like this:

I think it's my method for checking if the Wrd is in the tree, because i'm having some trouble writing it.

any suggestions about where i may have gone wrong?
 
Carey Brown
Bartender
Posts: 2980
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have one 'Occur' counter regardless of the number of words. You need to associate a different count with each unique word. Consider a HashMap<String,Integer>.
 
Kirstie Fran
Ranch Hand
Posts: 33
Android Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:Consider a HashMap<String,Integer>.

Can i get some help with implementing that please?
Where should i put it? I already have two methods, one to open the file and create a tree form it, the second is to sort it with an InOrder traversal. I'm thinking to place it after the second method, at the end.
How do I link it to the tree so that it can search it?
Lets say i were to use something like this:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!