Tree: Postorder Traversal

PROBLEM :

Complete the postOrder function in your editor below, which has  parameter: a pointer to the root of a binary tree. It must print the values in the tree's postorder traversal as a single line of space-separated values.

Input Format

Our hidden tester code passes the root node of a binary tree to your postOrder function.

Output Format

Print the tree's postorder traversal as a single line of space-separated values.

Sample Input

        4
       /   \
     2     7
    / \   /
 1   3 6

output : 1 3 2 6 7 4
--------------------------------------------------------------------------------
SIMPLE c++ IMPLEMENTATION :
--------------------------------------------------------------------------------

/* 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) {
   
    if(root==NULL)
        return ;
 
    postOrder(root->left) ;
    postOrder(root->right) ;
    cout<<root->data<<" " ;
}



---------------------------------------------------------------------------------

Comments

Popular posts from this blog

Count ways to N'th Stair(Order does not matter)

Replace all ‘0’ with ‘5’ in an input Integer

Chocolate Distribution Problem

Remove characters from the first string which are present in the second string

Primality Test ( CodeChef Problem code: PRB01 )