Hi, It did traverse your binary tree. However, your call to printf is only performed with the first(?) node.
I think this is how to accomplish what you want.
---- snippet+ ---
{
....
treerecurse(root); // you don't need a loop here
....
}
struct tnode *treerecurse(struct tnode *p) {
if(p != NULL) {
treerecurse(p->left);
printf("%4d %s\n", p->count, p->word); // perform what
// you desire for
// each entry
treerecurse(p->right);
}
}
---- snippet- ----
Hope this helps,
Joel
On Thu, 2005-01-27 at 07:01, J. wrote:
> 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.
>
> -
> To unsubscribe from this list: send the line "unsubscribe
> linux-c-programming" in
> the body of a message to [EMAIL PROTECTED]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
- Brian W. Kernighan
signature.asc
Description: This is a digitally signed message part
