#ifndef DICTIONARY_H #define DICTIONARY_H #include #include #include using namespace std; const int ALPHABET_SIZE = 26; struct Node { // Your data structure goes here struct Node...

1 answer below »
I completed the code, but it run problems, need help to debug


#ifndef DICTIONARY_H #define DICTIONARY_H #include #include #include using namespace std; const int ALPHABET_SIZE = 26; struct Node { // Your data structure goes here struct Node *character[ALPHABET_SIZE]; bool isEndofWord; }; class Dictionary { public: Dictionary(); Dictionary(string file); void addWord(string word); bool isWord(string word); bool isPrefix(string word); int wordCount(); void display(); private: Node* root; int numWords; // Any private methods you need/want }; Dictionary::Dictionary() { root = new Node; for (int i =0; icharacter[i] = nullptr; } root->isEndofWord = false; //numWords =0; } Dictionary::Dictionary(string file) { //Dictionary(); root = new Node; for (int i =0; icharacter[i] = nullptr; } root->isEndofWord = false; fstream InputFile; InputFile.open(file,ios::in); if(InputFile.fail()) cout<" error,="" cannot="" open="" file";="" else="" {="" string="" line;="" numwords="0;" while="" (inputfile="">>line) { //cout<"open successfully\n";="" addword(line);="" numwords++;="" }="" }="" }="" int="" dictionary::wordcount()="" {="" return="" numwords;="" }="" void="" dictionary::addword(string="" word)="" {="" node*="" newnode="new" node;="" for="" (int="" i="0;">character[i] =nullptr;} //newNode->isEndofWord = false; Node* currentNode = root; for(int i =0;i<"index:"><><"\n"; if(!currentnode="" -="">character[index]) currentNode->character[index] =newNode; currentNode = currentNode->character[index]; } currentNode->isEndofWord = true; } bool Dictionary::isPrefix(string word) { Node* currentNode = root; for (int i =0; icharacter[index]==nullptr) return false; currentNode = currentNode ->character[index]; } return currentNode != nullptr; } bool Dictionary::isWord(string word) { Node* currentNode = root; for (int i =0; icharacter[index]==nullptr) return false; currentNode = currentNode->character[index]; } return (currentNode ->isEndofWord && currentNode !=nullptr); } void Dictionary::display() { string test; Node* currentNode = root; for (int i =0; i <26; i++)="" {="" if(currentnode-="">character[i]) { test[8] = i+ 'a'; cout
Answered Same DayOct 24, 2021

Answer To: #ifndef DICTIONARY_H #define DICTIONARY_H #include #include #include using namespace std; const int...

Sudipta answered on Oct 25 2021
142 Votes
#include
#include
#include
using namespace std;
struct Node {
//
Node structure is here
public:
bool end;
// 26 letter next level nodes
Node *child[26];
// initialization of the node
Node() {
for(int i=0;i<26;i++){
this->child[i] = NULL;
}
end = false;

}
};
class Dictionary
{
private:
//root node
Node* root;
// no of words in the dictionary
int numWords;

public:
//1st constructor
Dictionary(){
this->root = new Node();
this->numWords = 0;
}
//2nd constructor
Dictionary(string file){
this->root = new Node();
this->numWords = 1;
addWord(file);
}
// function for adding the word to the dictionary
void addWord(string word){
Node *temp = this->root;
for(int...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here