C++ Help
|
Newbie Member
|
|
| 5Jun2007,04:52 | #1 |
|
Hi my name is Javier, I am Computer science major. I need help with Binary tree operations. I need some help writing a non-recursive c++ function that counts the number of leafs in a tree?? Thanks you
|
|
Light Poster
|
|
| 6Jun2007,01:15 | #2 |
|
i think this code wil help
Code:
nodeptr stack[MAX_SIZE];
inorder(nodeptr node)
{
int i = 0;
while(1)
{
for(;node;node = node -> left)
add(node); // adding node to stack
node = pop(); // pop from stack
if(!node->rchild && !node->lchild)
i++;
node = node->rchild;
}
printf("no of leaf nodes = %d",i);
}
Last edited by shabbir; 6Jun2007 at 08:37.. Reason: Code block - http://www.go4expert.com/forums/misc.php?do=bbcode#code |
|
Team Leader
|
![]() |
| 6Jun2007,05:15 | #3 |
|
Karri, please read the "Before you post a query" thread; specifically, learn to use code tags.
|
|
Go4Expert Founder
|
![]() |
| 6Jun2007,08:38 | #4 |
|
Quote:
Originally Posted by DaWei |


