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
Can we search the data in a linked list?
What type of algorithm is binary search?
What is push and pop in stack?
What is the most used data structure?
Reverse a linked list from the middle.
How does bogo sort work?
What sorting algorithm does arrays sort use?
Is treeset synchronized?
What is the two-dimensional array?
Is array faster than arraylist?
Why is hashmap not thread safe?
Is red black tree balanced?
State the different types of linked lists?
How does the size of arraylist increases dynamically?
What is the idea behind splaying?