diff --git a/bintree.c b/bintree.c index 5cf82a9..b04b4ec 100644 --- a/bintree.c +++ b/bintree.c @@ -26,11 +26,19 @@ void *nextTreeData(TreeNode *root) // Releases all memory resources (including data copies). void clearTree(TreeNode *root) { - + if (root == NULL) { + clearTree(root->left); + clearTree(root->right); + free(root->data); + free(root); + } } // Returns the number of entries in the tree given by root. unsigned int treeSize(const TreeNode *root) { - + if (root == NULL) { + return 0; + } + return 1 + treeSize(root->left) + treeSize(root->right); } \ No newline at end of file