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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---

Reply via email to