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
Is queue fifo or lifo?
How do you use merge sort?
How will you sort the elements of array in descending order?
Which collection is fail safe?
Does arraylist maintain insertion order?
Describe full binary tree and complete binary tree.
Complete structure of hashmap, very detail description, along with the basic coding of the hashmap internal implementation.
Explain linear linked implementation of Stack and Queue?
What is harvesting in agriculture?
What is data and data structure?
What is circular linked list?
In an avl tree, at explain what condition the balancing is to be done?
Is an arraylist an object?
Why null is not allowed in treemap?
What is the purpose of sorting?