implemented clearTree and treeSize functions

This commit is contained in:
pvtrx 2025-12-10 16:47:33 +01:00
parent 4741345749
commit 49ba00aad6

View File

@ -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);
}