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 do you mean by Syntax Error
Give the example of validating the parenthesis of expression using stack.
Is quicksort recursive?
What are the advantages of linked list over array (static data structure)?
What is the use of hashtable?
What is difference between array and string?
What do you mean by union-by-weight?
What do you mean by probing?
What are the applications of priority queues?
What is sequential search?
Define shortest path?
Is unordered_map a hash table?
Write an algorithm to show various operations on ordered list and arrays
What is data structure and its types?
Does the minimal spanning tree of a graph give the shortest distance between any 2 specified nodes?