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
What is the Insertion Sort Code?.
Why do we need linked list?
What is circular queue in data structure?
What is bitonic search?
What are the disadvantages of linear list?
Is priority queue sorted?
How do signed and unsigned numbers affect memory?
Is arraylist fail fast?
What is ds tree?
What is vector and types of vector?
Explain the uses of b+ tree.
Should I use hashmap or hashtable?
Can we insert null in hashset?
How will you check the validity of an expression containing nested parentheses?
Can treemap have duplicate values?