From b2b6f6a8963e52e10c279768b2351a2632a817c1 Mon Sep 17 00:00:00 2001 From: Pascal Siepe Date: Thu, 12 Nov 2026 15:27:52 +0100 Subject: [PATCH] clearTree implementation --- Startcode/bintree.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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.