Hi, Consider the case given below, 2 1 NULL
The post order should be <1, 2> ( ignoring the NULL ). Your algo gives <2> as the result. Pin point me if I'm wrong. Thanks and Regards, K.V.Chandra Kumar. On 24/08/07, Phani Kumar Ch. V. <[EMAIL PROTECTED]> wrote: > > Hi all, > > Please let me know if this pseudo code gives correct solution for > iterative post-order traversal of a binary tree. > ---------------------------------------------------- > void postOrderTraversal(Tree *root) > { > node * previous = null; > node * s = null; > push(root); > while( stack is not empty ) > { > s = pop(); > > if(s->right == null and s->left == null) > { > previous = s; > process node s; > } > else > { > if( s->right == previous or s->left == previous ) > { > previous = s; > process node s; > } > else > { > push( s ); > if(s->right) { push(s->right); } > if(s->left) { push(s->left); } > } > } > } > ----------------------- > Regards > Phani > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/algogeeks -~----------~----~----~----~------~----~------~--~---