Implement treeSize() and update clearTree()
This commit is contained in:
@@ -78,8 +78,8 @@ 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);
|
||||
}
|
||||
Reference in New Issue
Block a user