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

Define static data structures?

533


Which is better hashset or treeset?

494


Will this code give error if I try to add two heterogeneous elements in the arraylist? And why?

501


Is hashmap sorted?

511


Why do we need sorting?

479






Can we increase the size of statically allocated array?

505


Why do we need to recycle?

452


Differentiate between queue and deque.

510


What are the advantages of data structure?

527


Is quicksort faster than merge sort?

489


Describe the types of data structures?

574


Can you change size of array once created?

452


Is priority queue sorted?

514


What are the different types of data type?

530


Suppose in an integer array, there is 1 to 100 number, out of one is duplicate, how to find?

539