I got problems implementing the trie-version of pset6.
Since I even got problems to identify the problem, I´m going to ask some questions during my elaboration.
Here is what what Valgrinds put out:
BUT the programm runs completly normal without any error, and when I use a smaller dictionary, valgrind doesn´t complain at all, saying all mallocs are freed.
First I thought something is wrong with my unload-function, but it´s actually too simple and straighforward:
unload function calls recursive helperfunction
ulhelper(root[i]);
then
for (iteration through array)
{
if (root[i] has child)
ulhelper(root[i]->child);
free(root[i]->child
}
Q1 When I count the mallocs and frees I free about 27 more often than I malloc, can I omit freeing NULL-Pointers?
So I assume the problem is in the load-function respectively the way I add nodes to the trie:
To keep track of my position in the trie I use 2 temporary nodes, and these 2 nodes cause the problems since I can´t free them without destroying the triestructure, hence I just initialzed them to NULL, so I don´t need to free them, but Valgrind still complains, so:
Q2 How do you keep track of your position in the trie? Is there a better/smarter/easier way?
Q3 My root is declared as an array of nodes "node* root[27]" since I saw no other way to store one letter words, but it makes the load function a little bit more complicated, is there a workaround?