Implement treeSize() and update clearTree()

This commit is contained in:
D2A62006 2025-12-07 19:08:02 +01:00
parent 7652d3ea7d
commit 06168693b7

View File

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