When I run my speller program, everything compiles fine and the results are accurate, but the check function seems to be way too slow (takes ~7seconds) compared to staff's version(~0.2 seconds) and so my program did not qualify for the Big Board. All other functions run as fast as the staff's. If anyone notices anything that is causing this delay, I would love to hear your thoughts. thank you!
Here are my results vs. the staff solution's :
Mine:
WORDS IN DICTIONARY: 143091
WORDS IN TEXT: 17756
TIME IN load: 0.02
TIME IN check: 7.00
TIME IN size: 0.00
TIME IN unload: 0.00
TIME IN TOTAL: 7.02
Staff's:
WORDS IN DICTIONARY: 143091
WORDS IN TEXT: 17756
TIME IN load: 0.02
TIME IN check: 0.01
TIME IN size: 0.00
TIME IN unload: 0.01
TIME IN TOTAL: 0.05
And here is my check function:
bool check(const char *word)
{
//hash word to obtain index for that word
int index = hash(word);
//access linked list at the index in the hash table and
//traverse linked list, looking for the word
node *cursor = table[index];
while (cursor != NULL)
{
if (strcasecmp(word, cursor->word) == 0)
{
return true;
}
cursor = cursor->next;
}
return false;
}