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 does p mean in physics?
Explain what is the difference between null and nul?
Do pointers store the address of value or the actual value of a variable?
What are high level languages like C and FORTRAN also known as?
Can true be a variable name in c?
Can variables be declared anywhere in c?
how to print the character with maximum occurence and print that number of occurence too in a string given ?
Are bit fields portable?
What is file in c preprocessor?
The difference between printf and fprintf is ?
What is an lvalue in c?
How do I send escape sequences to control a terminal or other device?
How many keywords are there in c?
Explain high-order and low-order bytes.
Write a program, where i have a grid with many cells, how many paths are possible from one point to other desired points.