How will inorder, preorder and postorder traversals print
the elements of a tree?
Answer Posted / meganathan
void inorder(node * tree)
{
if(tree != NULL)
{
inorder(tree->leftchild);
printf("%d ",tree->data);
inorder(tree->rightchild);
}
else
return;
}
void postorder(node * tree)
{
if(tree != NULL)
{
postorder(tree->leftchild);
postorder(tree->rightchild);
printf("%d ",tree->data);
}
else
return;
}
void preorder(node * tree)
{
if(tree != NULL)
{
printf("%d ",tree->data);
preorder(tree->leftchild);
preorder(tree->rightchild);
}
else
return;
}
| Is This Answer Correct ? | 54 Yes | 10 No |
Post New Answer View All Answers
Difference between arrays and linked list?
Which sorting is used in collections sort?
Why is arraylist used?
What are the main differences between the linked list and linear array?
Can you sort a hashmap?
What is difference between array and arraylist? When will you use array over arraylist?
What is two-dimensional array?
What are the applications of priority queues?
List the limitations of linear probing?
What do you mean by 2-3 tree?
What are the different types of sorting in data structure?
Is hashtable better than dictionary?
Do sets allow duplicates?
What is the capacity of arraylist?
Explain what is B-tree?