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
Explain what is the difference between functions getch() and getche()?
Is it possible to have a function as a parameter in another function?
Is it better to use malloc() or calloc()?
How can I read in an object file and jump to locations in it?
What is || operator and how does it function in a program?
Write a program to reverse a string.
How can this be legal c?
What is a far pointer in c?
How can I manipulate individual bits?
What is typedef example?
What are # preprocessor operator in c?
How old is c programming language?
What are preprocessor directives in c?
write a program to find the given number is prime or not
Difference between Function to pointer and pointer to function