diff --git a/Startcode/bintree.c b/Startcode/bintree.c index ce4a24c..75f8c8f 100644 --- a/Startcode/bintree.c +++ b/Startcode/bintree.c @@ -26,7 +26,19 @@ void *nextTreeData(TreeNode *root) // Releases all memory resources (including data copies). void clearTree(TreeNode *root) { - + if(root->left != NULL){ + clearTree(root->left); + free(root->left->data); + free(root->left); + root->left = NULL; + } + + if(root->right != NULL){ + clearTree(root->right); + free(root->right->data); + free(root->right); + root->right; + } } // Returns the number of entries in the tree given by root.