I've implemented my load and check functions using tries. The program works fine and produces the output, but when I compared it against the output from staff's implementation, I found out that there were some discrepancies. For example, let's say we load the "large" dictionary and check "tolstoy.txt". I expected my program to write out the words that were exclusive to tolstoy.txt, but instead, it's the other way around.
My program returns words that are exclusive to "large" dictionary and cannot be found on tolstoy.txt. Have a look at my program.
#define Alphabet 27
struct node
{
bool end;
struct node* children[Alphabet];
};
/**
* Returns true if word is in dictionary else false.
*/
bool check(const char* word)
{
struct node* move = head;
int index = 0;
int j = 0;
while (word[j] != '\0')
{
if(word[j] == '\'')
{
index = Alphabet - 1;
}
else
{
index = toupper(word[j]) - 'A';
}
if(move->children[index] != NULL)
{
move = move->children[index];
j++;
}
else
{
move->end = false;
//printf("Not Found\n");
break;
}
}
if(word[j] == '\0' && move->end == true)
{
return true;
}
else
{
return false;
}
}
[edit: unrelated code removed for Honor Code compliance.]
I've been solving this problem non-stop for a week now and I'm thoroughly exhausted. Any help would mean the world to me. Thanks!