Postorder traversal of a binary tree
struct NODE
{
struct NODE *left;
int value; /* can take any data type */
struct NODE *right;
};
postorder(struct NODE *curr)
{
if(curr->left != NULL) postorder(curr->left);
if(curr->right != NULL) postorder(curr->right);
printf("%d", curr->value);
}
In a preorder traversal, first (pre) the root is visited and then the left & right sub- trees are traversed. In a postorder traversal, first the left sub-tree is visited, followed by right sub-tree which is then followed through root. In inorder traversal, first the left sub- tree is visited, followed by root, followed by right sub-tree.