In this program, we are going to modify the linked (non-array) binary tree so th
ID: 3695455 • Letter: I
Question
In this program, we are going to modify the linked (non-array) binary tree so that it acts as a general tree that stores a dictionary of words. Assuming that words are stored as sequences of characters, the letters can be treated as being in certain positions, just like they are in strings. For example, the word HAT has 3 letters, H in position zero, A in position one, and T in position 2. The words must be stored where each node's right pointer points to letters in the same position in a word (making a 'row' of letters that are in that position) while left pointers move to the next 'row' of letters that might store the next letter in the word. Here's an example that stores the words CAT, CATCH, CATS, and COP. Modifications to the BinaryTree class. Rename the class so that it is called ''DictionaryTree". Change elementType into type char. Add a bool called 'wordEnd' to the node structure. This will be set to true when the node constitutes the end of a word. In the example on the right, the nodes for 'T', 'H', 'S', and 'P' would be marked as ends of words. Add two modules: one that loads the words from "DictionaryWords.txt'' into the tree structure as described, and another that finds words in the dictionary tree. The word finder module must accept a string class object as a parameter and return a bool based on what it discovers. If the string is found in the dictionary and is a word, return true. Return false otherwise. This module may assume that all letters will have been converted to lowercase. Driver Details: Load the words from the file "dictionary.txt" into your tree, then ask the user to enter a word to see if it is in the dictionary. Find out if the user-entered word is in the dictionary and report the results to the screen. Repeat until the user enters "-" (two hyphens). Remember that the words entered here will not be found if they contain uppercase letters.Explanation / Answer
#include #include #include struct tree_node { tree_node *left; tree_node *right; int data; } ; class bst { tree_node *root; public: bst() { root=NULL; } int isempty() { return(root==NULL); } void insert(int item); void inordertrav(); void inorder(tree_node *); void postordertrav(); void postorder(tree_node *); void preordertrav(); void preorder(tree_node *); }; void bst::insert(int item) { tree_node *p=new tree_node; tree_node *parent; p->data=item; p->left=NULL; p->right=NULL; parent=NULL; if(isempty()) root=p; else { tree_node *ptr; ptr=root; while(ptr!=NULL) { parent=ptr; if(item>ptr->data) ptr=ptr->right; else ptr=ptr->left; } if(itemdata) parent->left=p; else parent->right=p; } } void bst::inordertrav() { inorder(root); } void bst::inorder(tree_node *ptr) { if(ptr!=NULL) { inorder(ptr->left); coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.