POSTORDER | TRAVERSAL TECHNIQUE

 POSTORDER  | TRAVERSING TECHNIQUE

A Short Trick

Let we understand the POSTORDER TRAVERSING TECHNIQUE from the following binary tree.

Suppose we have any binary tree such as:

80 , 50 , 100 , 45 , 95 , 110 , 47 , 99 , 115 , 97




Now we find  Postorder sequence of following binary tree.

First mark every node at the right side of node like




Now we will start traversing from node 47 like



Now we get the following postorder sequence:

POSTORDER: 47 , 45 , 50 , 97 , 99 , 95 , 115 , 110 , 100 , 80


RECURSIVE FUNCTION FOR POSTORDER


 

void postorder(structnode *root) 
{
     if (root != NULL) 
     {
         postorder( root➜lc )
         postorder( root➜rc);
         prinff("%d", root➜data);
    }
}

No comments:

Post a Comment