How would you print out the data in a binary tree, level by
level, starting at the top?
Answer Posted / hardik
To Print data in binary tree..a recursive function should be
used here post for postorder, in for inorder & pre for
rpeorder...
void post(struct node *temp)
{
if(temp->lptr!=NULL)
post(temp->lptr);
if(temp->rptr!=NULL)
post(temp->rptr);
if(temp!=NULL)
printf("%d\t%s\t%d\n",temp->rollno,temp->name,temp->marks);
}
void pre(struct node *temp)
{
if(temp!=NULL)
printf("%d\t%s\t%d\n",temp->rollno,temp->name,temp->marks);
if(temp->lptr!=NULL)
pre(temp->lptr);
if(temp->rptr!=NULL)
pre(temp->rptr);
}
void in(struct node *temp)
{
if(temp->lptr!=NULL)
in(temp->lptr);
if(temp!=NULL)
printf("%d\t%s\t%d\n",temp->rollno,temp->name,temp->marks);
if(temp->rptr!=NULL)
in(temp->rptr);
}
Is This Answer Correct ? | 2 Yes | 27 No |
Post New Answer View All Answers
What is an endless loop?
What is switch in c?
What is void c?
What is getch() function?
Tell me what is the purpose of 'register' keyword in c language?
Are local variables initialized to zero by default in c?
Write a program to print all permutations of a given string.
How can you restore a redirected standard stream?
What are the different types of constants?
What are structure types in C?
What is the basic structure of c?
Explain what is a 'locale'?
Why string is used in c?
Can you write a programmer for FACTORIAL using recursion?
What is the scope of static variables in c language?