AKIRA
Tank
- Joined
- Feb 6, 2006
- Messages
- 3,000
- Reaction score
- 2
How do I go about getting the size of a tree?
So far:
Function I need to create:
I did the base case, which is obviously if the tree is NULL, but I can't figure out how to get the size of the tree. I know that to get the size of a non-empty tree means that it's 1 plus the sizes of its left and right subtrees, but I don't know how to actually implement that..any help is greatly appreciated, thanks! :cheers:
So far:
Code:
void PrintPostOrder(BinaryTreeNode* root)
{
if (root != NULL) {
PrintPostOrder(root->left);
PrintPostOrder(root->right);
printf("%d ", root->item);
}
}
Function I need to create:
Code:
int GetSize(BinaryTreeNode* root)
{
if (root == NULL)
return 0;
else {
int
}
return -1;
}
I did the base case, which is obviously if the tree is NULL, but I can't figure out how to get the size of the tree. I know that to get the size of a non-empty tree means that it's 1 plus the sizes of its left and right subtrees, but I don't know how to actually implement that..any help is greatly appreciated, thanks! :cheers: