So I have a completed program that adds values into a binary tree. It then can list values in pre-order, post-order, and in order. Now everything works very dandy, except when I run my deleteAll function it makes the program unstable, and randomly when adding values, or listing the tree it can produce a segmentation fault. I’m not exactly sure what’s wrong, I’m still new to C, and cannot grasp what is causing it. It’s obviously in the deleteAllfunction, so here it is…
void deleteAll(node* *hd){
node* curr = *hd;
if(curr->left != NULL){
deleteAll(&curr->left);
}
if(curr->right != NULL){
deleteAll(&curr->right);
}
free(curr);
}
After I delete all and list in any order it will give me values such as 321294124, you know values given when it’s non-existant. So I assume that’s okay, but maybe that’s the problem.
Figured it out, thanks arrowdodger.