0

I managed to correctly write my speller using a hashtable, however the speller function did not return the correct number of words in dictionary so I had to take another method, but the question remained: Why doesn't the speller function recognized the hashtable previously loaded with data from dictionary? Here is my code:

// Returns number of words in dictionary if loaded else 0 if not yet loaded
unsigned int size(void)  
{  
int count_words = 0;  
for (int i = 0; i < N; i++)  
{  
    while (hashtable[i] != NULL)  
    {  
        count_words++;  
        hashtable[i] = hashtable[i]->next;  
    }  
}  
return count_words;  

}

1 Answer 1

1

This code accidentally destroys the hash table, leaving the nodes unreachable.

Instead of operating directly on hashtable[i], declare a new variable and set it to hashtable[i], and use that one to walk the structure, without changing hashtable entries.

Or, remember number of words in load, and return that. But you should be able to do both.

1
  • Thank you very much! I changed as per your advice and it worked. Thank you again!
    – Cristina N
    Commented Feb 23, 2019 at 7:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .