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


Please Help Members By Posting Answers For Below Questions

Define non linear data structure.

762


What is bitonic search?

750


Is radix sort stable?

708


Can we insert null in set?

673


Mention the data structures which are used in graph implementation.

694


Explain what are the major data structures used in the network data model?

785


Draw a binary Tree for the expression : A * B - (C + D) * (P / Q)

1188


What is data structure definition?

686


How many passes are required in bubble sort?

642


Can we add heterogeneous elements into treemap?

737


How do you sort a map by key?

667


What is a dequeue?

746


How does hashset work internally in java?

735


What is link list in data structure?

702


What sorting algorithm does arrays sort use?

642