Implement treeSize() and update clearTree()
This commit is contained in:
parent
7652d3ea7d
commit
06168693b7
@ -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);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user