generated from freudenreichan/info2Praktikum-DobleSpiel
implemented clearTree and treeSize functions
This commit is contained in:
parent
4741345749
commit
49ba00aad6
12
bintree.c
12
bintree.c
@ -26,11 +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 == NULL) {
|
||||||
|
clearTree(root->left);
|
||||||
|
clearTree(root->right);
|
||||||
|
free(root->data);
|
||||||
|
free(root);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the number of entries in the tree given by root.
|
// Returns the number of entries in the tree given by root.
|
||||||
unsigned int treeSize(const TreeNode *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