clearTree implementation

This commit is contained in:
siepepa103492 committed 2026-11-12 15:27:52 +01:00
1 parent 942c816dfc
commit b2b6f6a896
1 file changed
+12
+12
View File
@@ -26,7 +26,19 @@ void *nextTreeData(TreeNode *root)
// Releases all memory resources (including data copies). // Releases all memory resources (including data copies).
void clearTree(TreeNode *root) 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. // Returns the number of entries in the tree given by root.