Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   preorder traversal (recursive) (http://www.go4expert.com/forums/preorder-traversal-recursive-t22102/)

silbhumi 14May2010 20:18

preorder traversal (recursive)
void preorder(NODE *Node)
printf("%c ", Node->data);

In the above program fragment even though the statement 'preorder(Node->leftchild)'
occurs before the statement 'preorder(Node->rightchild)' the actual execution of the program shows that after printing the head node with the help of 'printf()', program control goes to 'preorder(Node->rightchild)'.

It seems that the issue here is related to SYSTEM STACK, but I am unable to say anything about it. Please try to explain in detail how such thing involving seemingly non-sequential execution comes into effect.

Also let me know about similar things occuring in postorder traversal of a binary tree.

Thanking you,



xpi0t0s 15May2010 14:48

Re: preorder traversal (recursive)
Without the rest of the program, the data given and the output received, it's impossible to say. From the code given, the second printf *willl* be of Node->leftchild->data, so it's impossible to say why you think it's rightchild.

All times are GMT +5.5. The time now is 16:37.