How will inorder, preorder and postorder traversals print
the elements of a tree?
Answer Posted / 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 View All Answers
Which language is best for learning data structures and algorithms?
Why does hashset use hashmap?
Model a data structure for a DFA that takes an event as parameter and performs a desired action.
What is significance of ” * ” ?
How do you sort a map by key?
What is the difference between push and pop?
What are the difference between malloc() and calloc()?
Mention the steps to insert data at the starting of a singly linked list?
Define an equivalence relation?
How to sort an Array?
What is a dequeue?
Why would you use a linked list?
What are the best data structure courses for gate preparation?
Is array faster than arraylist?
Can we change the size of an array at run time?