Question: please convert this code to (c) language _________________________________________________ Solution 1.) #include DictionaryGenerator_H.h DictionaryGenerator::DictionaryGenerator() //- Default Constructor { wordCount = 0; //- Initialising the values ptrRoot

please convert this code to (c) language _________________________________________________

Solution 1.)

#include "DictionaryGenerator_H.h" DictionaryGenerator::DictionaryGenerator() //- Default Constructor { wordCount = 0; //- Initialising the values ptrRoot = NULL; //- Initialising the values } DictionaryGenerator::~DictionaryGenerator() //- Default Destructor { DeleteInOrder(ptrRoot); //- Deletes the tree in order and clears the memory } int DictionaryGenerator::numberOfWordsInBST() //- Returns the number of words contained in the dictionary. { return wordCount; } DictionaryGenerator::BstNode* DictionaryGenerator::DeleteWord( BstNode* ptrRoot, char* word ) //- Deletes the specified word from the Binary Search Tree. { if ( ptrRoot == NULL ) { return ptrRoot; } else if ( word < ptrRoot -> word ) { ptrRoot -> left = DeleteWord( ptrRoot -> left, word ); } else if ( word > ptrRoot -> word ) { ptrRoot -> right = DeleteWord( ptrRoot -> right, word ); } else //- Found the node to be deleted. { if ( ptrRoot -> left == NULL && ptrRoot -> right == NULL ) //- Case 1: Node to be deleted has no children. { delete ptrRoot; ptrRoot = NULL; } else if ( ptrRoot -> left == NULL ) //- Case 2: Node to be deleted has one child node. { BstNode* temp = ptrRoot; ptrRoot = ptrRoot -> right; delete temp; } else if ( ptrRoot -> right == NULL ) //- Case 2: Node to be deleted has one child node. { BstNode* temp = ptrRoot; ptrRoot = ptrRoot -> left; delete temp; } else //- Case 3: Node to be deleted has 2 children { BstNode* temp = FindNodeContainingFirstWord( ptrRoot -> right ); ptrRoot -> word = temp -> word; ptrRoot -> right = DeleteWord( ptrRoot -> right, temp -> word ); } } wordCount--; //- Decreases wordCount by 1; return ptrRoot; } DictionaryGenerator::BstNode* DictionaryGenerator::InsertWord( BstNode* ptrRoot, char* word ) //- Inserts a word into the Binary Search Tree. { if ( ptrRoot == NULL ) //- Checks to see if BST is empty { ptrRoot = CreateNewBstNode( word ); } else if ( word[0] < ptrRoot -> word[0] ) //- Checks to see if the word to be inserted is <=, if so then it is inserted into the left hand side of the BST subtree. { ptrRoot -> left = InsertWord( ptrRoot -> left, word ); //- Inserting the word into the tree. ptrRoot = BalanceTree(ptrRoot); //- Balancing the word in the tree. } else if ( word[0] == ptrRoot -> word[0] ) //- This here is for when char's are equal. { int i = 0; while ( word[i] == ptrRoot -> word[i]) //- Loop until there is a difference between the two. { if ( word[i] == '\0' && ptrRoot -> word[i] == '\0' ) //- If this happens then the word must be the same. So we do not add it to the BST { /*std::cout << " " << "Gracefully Handling Insertion of Existing Word in BST. Word = " << ptrRoot -> word<< " " << std::endl; */ //- Used for validation testing return ptrRoot; //- Does not insert as current Node is the same. } i++; //- Iterate the count } if ( word[i] < ptrRoot -> word[i] ) { ptrRoot -> left = InsertWord( ptrRoot -> left, word ); //- Inserting the word into the tree. ptrRoot = BalanceTree(ptrRoot); //- Balancing the word in the tree. } else { ptrRoot -> right = InsertWord( ptrRoot -> right, word ); //- Inserting the word into the tree. ptrRoot = BalanceTree(ptrRoot); //- Balancing the word in the tree. } } else //- Word must be larger, so insert into the right hand side of the BST subtree { ptrRoot -> right = InsertWord( ptrRoot -> right, word ); //- Inserting the word into the tree. ptrRoot = BalanceTree(ptrRoot); //- Balancing the word in the tree. } return ptrRoot; //- Returns the prtRoot of the node } bool DictionaryGenerator::SearchBST( BstNode* ptrRoot, char* word ) //- Searches the Binary Search Tree for the specified word in the BST. { if ( ptrRoot == NULL ) { return false; //- Returns false as the function has reached the end of the tree and word not found. } else if ( ptrRoot -> word[0] == word[0] ) { return true; //- Word found } else if ( word[0] <= ptrRoot -> word[0] ) { return SearchBST( ptrRoot -> left, word ); //- Search for word in the left node. } else { return SearchBST( ptrRoot -> right, word ); //- Search for word in the right node } } char* DictionaryGenerator::FindFirstWord( BstNode* ptrRoot ) //- Searches the Binary Search Tree for the first word in the Dictionary in Alphabetical Order. E.G - This is equivilant to finding the smallest number in the BST e.g findMin() { while( ptrRoot -> left != NULL ) //- Iterating until the end, always moving to the left node { ptrRoot = ptrRoot -> left; } return ptrRoot -> word; //- Return the first word stored in the tree. } void DictionaryGenerator::CheckInOrder( BstNode* ptrRoot ) //- Prints out the Words of the BST in alphabetical order, So user can verify if BST is in order. Note: If output is not in alphabetical order then the BST is not ordered correctly. { if ( ptrRoot == NULL ) return; //- Returns when ptrRoot is equal to NULL CheckInOrder( ptrRoot -> left ); //- Check the Left Hand side of the BST Subtree //std::cout << ptrRoot -> word << std::endl; //- Printing out the word CheckInOrder( ptrRoot -> right ); //- Check the Right Hand side of the BST Subtree //std::cout << ptrRoot -> word << std::endl; //- Printing out the word }

Solution 2.)

#include "util.h" #include "DictionaryHashtable.h" bool DictionaryHashtable::insert(std::string word) { if(word==""){ return false; //if inserting empty string, return false } return get<1>(dict.insert(word)); //get the bool value from the pair and return } /* Return true if word is in the dictionary, and false otherwise */ bool DictionaryHashtable::find(std::string word) const { if(dict.find(word)!=dict.end()){ return true; //word found! } return false; //word not found in the dictionary } /* Destructor */ DictionaryHashtable::~DictionaryHashtable(){} //just use the default (trivial) destructor

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!