From 49ba00aad63a18cd216e84952a848b624fa202a5 Mon Sep 17 00:00:00 2001 From: pvtrx Date: Wed, 10 Dec 2025 16:47:33 +0100 Subject: [PATCH] implemented clearTree and treeSize functions --- bintree.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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