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<<" " ;
}
---------------------------------------------------------------------------------
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
Post a Comment