How will inorder, preorder and postorder traversals print
the elements of a tree?

Answer Posted / soma gidugu

void inorder(node * root)
{
if(root!= NULL)
{
inorder(root->leftchild);
printf("%d ",root->data);
inorder(root->rightchild);
}
else
return;

}

void postorder(node * root)
{
if(root!= NULL)
{
postorder(root->leftchild);
postorder(root->rightchild);
printf("%d ",root->data);
}
else
return;
}

void preorder(node * root)
{
if(root!= NULL)
{
printf("%d ",root->data);
preorder(root->leftchild);
preorder(root->rightchild);
}
else
return;

}

Is This Answer Correct ?    13 Yes 7 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can we store null in arraylist?

672


In what scenario, binary search can be used?

748


Is merge sort better than quick?

713


Is hashset a collection?

679


Is null allowed in list?

624


Is it possible to insert different type of elements in a stack? How?

741


Calculate the efficiency of sequential search?

756


What is the order of selection sort?

633


Is there any difference between int[] a and int a[]?

787


What is garbage collection in data structure?

734


What are the advantages of data structure?

736


Describe the degree term in a tree.

761


What is a treemap chart?

646


What does a bubble chart show?

655


Can you change size of array once created?

652