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
Define static data structures?
Which is better hashset or treeset?
Will this code give error if I try to add two heterogeneous elements in the arraylist? And why?
Is hashmap sorted?
Why do we need sorting?
Can we increase the size of statically allocated array?
Why do we need to recycle?
Differentiate between queue and deque.
What are the advantages of data structure?
Is quicksort faster than merge sort?
Describe the types of data structures?
Can you change size of array once created?
Is priority queue sorted?
What are the different types of data type?
Suppose in an integer array, there is 1 to 100 number, out of one is duplicate, how to find?