Iterative Traversal of a binary tree..
Srinivas Ponugupaty <[email protected]> Thu, 5 May 2005 15:36:32 -0700 (PDT)
| Newsgroups | gmane.comp.programming.cppug |
|---|---|
| Message-ID | <[email protected]> |
Hi All :-
I am trying to implement a routine to traverse a
binary tree without recursion or using a stack.
The code is below.However I am am not able to get all
the nodes in the binary tree..where am i going wrong.
Thanks
void display ( struct node * head )
{
struct node * ptr , * temp ;
ptr = head ;
while ( ptr != NULL )
{
printf("%d\t",ptr->data ) ;
if ( ptr->left != NULL )
ptr = ptr->left ;
else if ( ptr->right != NULL )
ptr = ptr->right ;
else
{
ptr = head->right ;
while ( ptr != NULL )
{
printf("%d\t",ptr->data ) ;
if ( ptr->left != NULL )
ptr = ptr->left ;
else if ( ptr->right != NULL )
ptr = ptr->right ;
else
return ;
}
}
}
Yahoo! Mail
Stay connected, organized, and protected. Take the tour:
http://tour.mail.yahoo.com/mailtour.html
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/cppug/
<*> To unsubscribe from this group, send an email to:
[email protected]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/