Tag Archives: iterative postorder traversal

Iterative postorder traversal in BST code in c

As far we have seen iterative inorder traversal in BST using stack. Most traversal are solved using stack in BST. Here iterative postorder traversal in BST also implemented using 2 stacks.

Approach :

Two stacks S1 & S2 

Stack2 (S2) is used only for output purpose only

step 1: push the root in  Stack S1

step2: pop the element from s1  and mark as current node then push into S2

step 3: if popped element has left element then push it into s1

step 4: if popped element has right element then push it into s1

step 5: Follow from step2 to step4 untill stack s1 is emply.

Step 6: Pop out and print the all element from s2


Function for iterative postorder traversal :


Complete C implementation with BST implementation and iterative postorder traversal  function