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


Please Help Members By Posting Answers For Below Questions

What does p mean in physics?

579


Explain what is the difference between null and nul?

649


Do pointers store the address of value or the actual value of a variable?

606


What are high level languages like C and FORTRAN also known as?

680


Can true be a variable name in c?

555






Can variables be declared anywhere in c?

614


how to print the character with maximum occurence and print that number of occurence too in a string given ?

2029


Are bit fields portable?

669


What is file in c preprocessor?

647


The difference between printf and fprintf is ?

714


What is an lvalue in c?

690


How do I send escape sequences to control a terminal or other device?

604


How many keywords are there in c?

586


Explain high-order and low-order bytes.

661


Write a program, where i have a grid with many cells, how many paths are possible from one point to other desired points.

696