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

Answer Posted / shital

typedef struct NODE
{
int data;
struct NODE *left,*right;
}node;

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

}

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

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

}

Is This Answer Correct ?    11 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How many types of linked list are there?

638


How do you determine if a binary tree is height balanced?

731


Explain what is the data structures used to perform recursion?

676


What is the use of threaded binary tree?

756


Why is arraylist used?

670


Tell me the difference between the character array and a string.

718


What is non linear structure?

678


Which sorting is best and why?

664


Is heap sort stable?

665


Write a program to sum values of given array.

740


What is binary tree? Explain its uses.

665


What is the best data structure and algorithm to implement cache?

726


Which sorting is best in time complexity?

705


What is the best sorting technique?

687


What is an recursive algorithm?

723