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

Answers were Sorted based on User's Feedback



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

Answer / narendra sharma

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

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

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

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

Is This Answer Correct ?    1 Yes 2 No

Post New Answer

More Data Structures Interview Questions

Which language is best for learning data structures and algorithms?

0 Answers  


What method is used to place a value onto the top of a stack?

0 Answers  


What the principle of quick sort and its complexity?

0 Answers   Honeywell, Zomato,


What are the different types of data structures explain briefly?

0 Answers  


How many pointers are necessary to implement a simple linked list?

0 Answers  






What is the default value of Array?

0 Answers  


Why is quicksort unstable?

0 Answers  


How do you clear a stack?

0 Answers  


What is the use of sorting?

0 Answers  


How to print element of Array?

0 Answers  


What is difference between arraylist and list?

0 Answers  


What type of variable is age?

0 Answers  


Categories