>i dont know how to write the code ?
Do you know how to do a preorder traversal? Once you have that, it's just a test whether both children are either null or not null. It's a short solution, so I can't give you example code without solving the problem for you.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
in language C
Code that examine if the tree is full
Tree is full if each node have 2 child
i dont know how to write the code ?
somebody can help me ?
It seems to me a tree cannever be full. The last node(s) will always have two free child positions, won't it?
WaltP
Posting Sage w/ dash of thyme
10,505 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
>The last node(s) will always have two free child positions, won't it?
A full tree in this case is one where every non-leaf node has two non-null children. For example:
a
/ \
b c
/ \ / \
d e f g
is a full tree, but
a
/ \
b c
\ / \
e f g
is not because b is neither a leaf nor has two non-null children.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
>The last node(s) will always have two free child positions, won't it?
A full tree in this case is one where every non-leaf node has two non-null children.
{pictire snipped] is not because b is neither a leaf nor has two non-null children.
Oh... OK. I didn't realize that was a definition. Thanks.
WaltP
Posting Sage w/ dash of thyme
10,505 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944