suppose this is the binary search tree
http://upload.wikimedia.org/wikipedi...earch_tree.svg
code for post order transversal
It will print 8 then 3 then 1Code:void preorder(struct tree *rt) { if(rt==NULL) { return; } printf("%d ",rt->info); preorder(rt->lchild); preorder(rt->rchild); }
after printing 1 this statement will execute
preorder(rt->lchild); because the left of node which contains 1 is NULL so in this recursive function preorder(rt->lchild); null will be passed. then root will also become NULL thats why this if statement will execute
Now what will happen after returning in which statement control will be passed ?Code:if(rt==NULL) { return; }



LinkBack URL
About LinkBacks




