Starting from:

$30

CECS275 - Lab 10 – BST- Solved

Word Frequency – Use the binary search tree given in the lecture notes to create a program that keeps track of duplicates by incrementing whenever the item is readded.  Then retrieve that counter whenever that value is searched for.

Word Class – Create a string word and an integer frequency.  Create a constructor, get methods, an incrementer for frequency, overload the <<, <, ==, and <= operators.  The << should return the string value and the frequency, and the relational operators should only compare the strings (not the frequency) and then return true or false.

Node and BST– Modify Node and the BST to take Words rather than ints. Modify the add method so that if the new word being added is equal to the item in the tree, it increments the frequency of the item in the tree, otherwise it should add the value normally.

Main Class – Create a main that reads in a text file, words in the file are separated by new lines.  Add these words to the BST.  Write a menu that allows the user to print out the list, or to search for a particular word, or to exit the program.  If the word the user searched for does not exist, state that it does not exist, otherwise print out the word with its frequency.  Error check the user’s input.

 

More products