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 are the pre-requisite for the collection to perform binary search?
How does selection sort work?
What are all the classes and interfaces that are available in the collections?
What is the complexity of adding an element to the heap?
How do you sort an array in descending order?
What sort of serious problems have you experienced, and how have you handled them?
What are the types of sorting?
What is unmodifiable list?
List the data structures which are used in network data modal.
What are the four characteristics of algorithms?
What are the types of array operations?
Mention some drawbacks of the linked list.
Is vector a collection?
Can we remove element from arraylist while iterating?
Can we insert null in hashset?