From 06168693b73d3224ee0a03e984716a5dbf42a6b0 Mon Sep 17 00:00:00 2001 From: D2A62006 Date: Sun, 7 Dec 2025 19:08:02 +0100 Subject: [PATCH] Implement treeSize() and update clearTree() --- bintree.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/bintree.c b/bintree.c index 59bfa9b..ece271f 100644 --- a/bintree.c +++ b/bintree.c @@ -78,9 +78,9 @@ void clearTree(TreeNode *root) return; } - clearTree(root->right); clearTree(root->left); - + clearTree(root->right); + free(root->data); free(root); @@ -89,5 +89,8 @@ void clearTree(TreeNode *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