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

Can we search the data in a linked list?

686


What type of algorithm is binary search?

641


What is push and pop in stack?

606


What is the most used data structure?

647


Reverse a linked list from the middle.

716


How does bogo sort work?

793


What sorting algorithm does arrays sort use?

626


Is treeset synchronized?

638


What is the two-dimensional array?

736


Is array faster than arraylist?

668


Why is hashmap not thread safe?

676


Is red black tree balanced?

677


State the different types of linked lists?

683


How does the size of arraylist increases dynamically?

635


What is the idea behind splaying?

1487