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

Is queue fifo or lifo?

488


How do you use merge sort?

442


How will you sort the elements of array in descending order?

592


Which collection is fail safe?

489


Does arraylist maintain insertion order?

469






Describe full binary tree and complete binary tree.

497


Complete structure of hashmap, very detail description, along with the basic coding of the hashmap internal implementation.

630


Explain linear linked implementation of Stack and Queue?

518


What is harvesting in agriculture?

499


What is data and data structure?

493


What is circular linked list?

523


In an avl tree, at explain what condition the balancing is to be done?

517


Is an arraylist an object?

481


Why null is not allowed in treemap?

494


What is the purpose of sorting?

481