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
Define leaves?
Is heap sort faster than quicksort?
Why do we need to use computers to help us sort lists?
What are the advantages and disadvantages of linked list over array?
What are linked lists used for?
Does hashset guarantee order?
What is stack in data structure with the example?
What are the basic data structures?
Write a data structure for a queue.
What is unmodifiable list?
Define circular list?
How do you do a heap sort?
What does bubble sort do?
What member function places a new node at the end of the linked list?
What are the pre-requisite for the collection to perform binary search?