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

What is meant by binary tree traversal?

0 Answers  


What is linked list ?

0 Answers  


What is comparator interface used for?

0 Answers  


Define path in a graph?

0 Answers  


Define circular list?

0 Answers  






What is linked hash set?

0 Answers  


What are the applications of linked list?

0 Answers  


Can nsarray contain nil?

0 Answers  


What do you mean by 2-3 tree?

0 Answers  


What is difference between arraylist and list?

0 Answers  


How many types of data structure are there?

0 Answers  


How do you represent a linked list?

0 Answers  


Categories