How will inorder, preorder and postorder traversals print
the elements of a tree?
Answer Posted / soma gidugu
void inorder(node * root)
{
if(root!= NULL)
{
inorder(root->leftchild);
printf("%d ",root->data);
inorder(root->rightchild);
}
else
return;
}
void postorder(node * root)
{
if(root!= NULL)
{
postorder(root->leftchild);
postorder(root->rightchild);
printf("%d ",root->data);
}
else
return;
}
void preorder(node * root)
{
if(root!= NULL)
{
printf("%d ",root->data);
preorder(root->leftchild);
preorder(root->rightchild);
}
else
return;
}
| Is This Answer Correct ? | 13 Yes | 7 No |
Post New Answer View All Answers
Can list contain null values?
Which list does not allow duplicates?
Is it legal to initialize list like this?
Explain binary representation?
What are the different types of sorting in data structure?
Why do we use collections?
Is array size dynamic or fixed?
What is the space complexity of bubble sort?
What happens if we put a key object in a hashmap which exists?
Explain the principle of quicksort. What is its complexity?
Can arraylist contain duplicates?
How many parts are there in a declaration statement using data structures?
What are basic algorithms?
What is time complexity of hashmap?
List out the advantages of using a linked list?