I'm supposed to be inserting words from a text file into a BST and AVL tree. I've got the words to insert correctly, and it recognizes whenever the words are repeated. It just leaves the count at 2 instead of incrementing afterwards. Can't seem to figure out why it's not taking the count at the moment it finds a repeat.
try
{
FileReader reader = new FileReader("mlkdream1.txt");
Scanner in = new Scanner(reader);
while (in.hasNext())
{
tmp = in.next();
tmp = tmp.toUpperCase();
word = new WordStat(tmp, 1);
if(!Bst1.inTree(word))
{
Bst1.insert(word);
Avl1.insert(word);
count++;
}
else
{
Avl1.retrieve(word);
word.updateCount(1);
Bst1.insert(word);
Avl1.insert(word);
}
}
reader.close();
The variable word
is of the type WordStat, which is defined as (String word, int frequency). The updateCount(Integer)
method is supposed to grab the original count, and increment it by the number passed to it. I don't think the retrieve
is wrong, because that was already written for us.
Any help would be much appreciated ;)