Tree: Inorder Traversal

PROBLEM :

Complete the inOrder 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 inorder 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 inOrder function.

Output Format

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

Sample Input

 4
       /   \
     2     7
    / \   /
  1   3 6

output : 1 2 3 4 6 7
--------------------------------------------------------------------------------
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 inOrder(node *root) {
   
    if(root==NULL)
            return ;
   
    inOrder(root->left) ;
    cout<<root->data<<" " ;
    inOrder(root->right) ;

}




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

Comments