Greetings.
I seek assistance with the data structure binary tree. Following is a brief description of the issue:
A binary tree is created with nodes of the tree being a struct containing a pointer each for the left & right branches. I have sucessfully achieved the creation. I am asked to now delete the tree one node at a time by deallocating the memory for each of the nodes using free().
Following code represents my attempt:
Code:
void freeTree(node *root){ //Tree's root note is passed as argument
while(1){
if(root == NULL){
break;
}
else if(root != NULL && root->left != NULL){
freeTree(root->left);
}
else if(root != NULL && root->right != NULL){
freeTree(root->right);
}
else{
free(root);
return;
}
}
}
A successful compilation results. However, on attempting execute the code, the following error is generated:
Code:
12 [sig] test_st1 7016 _cygtls::handle_exceptions: Error while dumping state (probably corrupted stack)
Segmentation fault (core dumped)
Would greatly appreciate assistance with addressing the issue.
Look forward to a prompt response.
Best regards,
wirefree101