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
What is priority queue in data structure?
How to cut or remove an element from the array?
What is list and its types?
Define an abstract data type (adt)?
What is sort in data structure?
Why is arraylist faster than linkedlist?
Is it legal to initialize list like this?
Explain exception filter?
What are red-black trees?
Does hashmap allow duplicate keys?
Can we use any class as map key?
Why is hashmap faster?
Give one example of right rotation.
Define a tree?
How does the size of arraylist increases dynamically?