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
How many types of search algorithms are there?
Does arraylist guarantee insertion order?
How do you assign an address to an element of a pointer array ?
Differentiate between the singly linked list and doubly linked list.
What is data structure and its operations?
Difference between calloc and malloc in data structures?
Can arraylist have duplicates?
What is the best sorting technique?
Which type of memory allocation is referred for linked list?
What does sorting an array do?
What is the complexity of bubble sort?
what is the biggest advantage of linked lists?
Explain about circular linked list?
Why do we use linked lists?
What is lifo?