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

Does linkedhashset allow duplicates?

434


Define balanced trees?

533


Is quicksort greedy algorithm?

511


What does simulation of queues mean?

578


What is entryset method in map?

477






Differentiate between hashset and hashmap.

518


Is array a data structure?

506


Explain how is linked list implemented?

529


Explain the internal working of a hash map?

512


What is a node in it?

552


What is the application of queue?

487


What is the best time complexity of bubble sort?

524


Why would you use a linked list?

474


Write the advantage of separate chaining?

481


What is adt in data structure?

494