linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* binary tree traversal...
@ 2005-01-26 23:01 J.
  2005-01-27  2:07 ` Eric Bambach
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: J. @ 2005-01-26 23:01 UTC (permalink / raw)
  To: linux-c-programming

Wednesday, January 26

Hello,

I am trying to traverse a binary tree, returning each node that is
encounterd so that I can preform operations on that node. However it keeps
looping over the same first node, it refuses to travel any further down
the tree ... What did I overlooked ? I know the tree is loaded with data
since a simple recursive preorder treeprint confirms that.

An example: 

 while((root = treerecurse(root)) != NULL)
  printf("%4d %s\n", root->count, root->word);

And the treerecurse function would look something like:

struct tnode *treerecurse(struct tnode *p) {
 if(p != NULL) {
  treerecurse(p->left);
  return p;
  treerecurse(p->right);
 }
}

I guess there is something wrong in my reasoning about this...

Thnkx..

J.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-01-30 11:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-01-26 23:01 binary tree traversal J.
2005-01-27  2:07 ` Eric Bambach
2005-01-27 20:06   ` J.
2005-01-27  3:19 ` Joel Pareja
2005-01-30 11:49 ` Glynn Clements

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).