Thursday, January 14, 2016

Tree: Postorder Traversal - Hacker Rank Solution

You are given a pointer to the root of a binary tree; print the values in post-order traversal.
You only have to complete the function.

Input Format
You are given a function,
void Postorder(node *root) {

}
Output Format
Print the values on a single line separated by space.
Sample Input
     3
   /   \
  5     2
 / \    /
1   4  6
Sample Output
1 4 5 6 2 3 
---------------------------------------------------------------------------------
/* you only have to complete the function given below.  
Node is defined as  

struct node
{
    int data;
    node* left;
    node* right;
};

*/


void Postorder(node *root) {
     struct node *temp;
    temp=root;
    if(temp!=NULL)
      {  
        Postorder(temp->left);
        Postorder(temp->right);
        printf("%d ",temp->data);
    }


}
---------------------------------------------------------------------------------- 
Powered by Blogger.