Amazon.com Interview Question
1,589 Interview Reviews |
Back to all Amazon.com Interview Questions & Reviews
Interview questions and reviews posted anonymously by interview candidates
Interview Question for Intern at Amazon.com:
Helpful Question?
Yes |
No
Inappropriate?
Answers & Comments (2)
It should be printing t -> val, not t -> left Sorry!
void inorder(tree t)
{
if(t == NULL)
return;
inorder(t -> left);
cout << t -> val << " ";
inorder(t -> right);
}
void preorder(tree t)
{
if(t == NULL)
return;
cout << t -> val << " ";
preorder(t -> left);
preorder(t -> right);
}
Since I'm already this far here is post order as well:
void postorder(tree t)
{
if(t == NULL)
return;
postorder(t -> left);
postorder(t -> right);
cout << t -> val << " ";
}
Helpful Answer?
Yes |
No
Inappropriate?
To comment on this
question,
Sign In with Facebook or
Sign Up



0 of 0 people found this helpful
by Basic Print inorder and preorder. C++:
{
if(t == NULL)
return;
inorder(t -> left);
cout << t -> left << " ";
inorder(t -> right);
}
void preorder(tree t)
{
if(t == NULL)
return;
cout << t -> left << " ";
preorder(t -> left);
preorder(t -> right);
}
Since I'm already this far here is post order as well:
void postorder(tree t)
{
if(t == NULL)
return;
postorder(t -> left);
postorder(t -> right);
cout << t -> left << " ";
}