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

What are the pre-requisite for the collection to perform binary search?

503


How does selection sort work?

550


What are all the classes and interfaces that are available in the collections?

503


What is the complexity of adding an element to the heap?

488


How do you sort an array in descending order?

505






What sort of serious problems have you experienced, and how have you handled them?

603


What are the types of sorting?

481


What is unmodifiable list?

517


List the data structures which are used in network data modal.

480


What are the four characteristics of algorithms?

473


What are the types of array operations?

500


Mention some drawbacks of the linked list.

572


Is vector a collection?

464


Can we remove element from arraylist while iterating?

505


Can we insert null in hashset?

519