COMP2000 – Assignment 2

$30.00

Category: Tags: , , , , You will Instantly receive a download link for .zip solution file upon Payment || To Order Original Work Click Custom Order?

Description

5/5 - (5 votes)

Write a program to read and store a thesaurus as follows.
Data for the program consists of lines of input. Each line contains a (variable) number of distinct words, all of which are synonyms. You may assume that words consist of letters only and are separated by one or more blanks. The words are to be stored in a binary search tree. The data structure must be organized such that, given any word, all synonyms for that word can be quickly found. A word can appear on more than one line, but each word must be inserted only once in the tree. If a word appears on more than one line then all words on those lines are to be considered synonyms.

After the complete thesaurus has been built, print an alphabetical listing of the words and their synonyms.

Print another alphabetical listing but, this time, each word is printed once only. That is, if a word is already printed as a synonym of another word then it does not appear in the listing again.

Sample data (read from the file input.txt)

blossom flower
bewilder confound confuse perplex
dwell live reside
—————————————————–
Output (sent to file output.txt)

Words Synonyms

bewilder confound confuse perplex
blossom flower
confound bewilder confuse perplex
confuse bewilder confound perplex
dwell live reside
flower blossom
live dwell reside
perplex bewilder confound confuse
reside dwell live

Words Synonyms

bewilder confound confuse perplex
blossom flower
dwell live reside