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
Is arraylist a class?
What are the major data structures used in the network data model?
Write an algorithm to show various operations on ordered list and arrays
Which interface treemap implements?
Is hashset a collection?
Explain the Stack
Which data structures are used in bfs and dfs algorithm?
What is difference between hashmap and arraylist?
What is the capacity of arraylist?
Can we add or delete an element after assigning an array?
What are the average and worst time complexity in a sorted binary tree is
Differentiate between hashmap and treemap.
How is heap sort implemented?
Differentiate null and void?
What is data structure explain in detail?