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

If I have a char * variable pointing to the name of a function ..

654


What are the header files used in c language?

590


What are the key features in c programming language?

618


Why do we need arrays in c?

587


Study the following C program :call_me (myvar)int myvar;{ myvar +- 5; }main(){int myvar;myvar = 3;call_me(myvar);printf("%d ",myvar);What will be printed a) 3 b) 5 c) 8 d) symbol

667






difference between object file and executable file

6097


What is the maximum length of an identifier?

667


In which header file is the null macro defined?

857


How can you increase the allowable number of simultaneously open files?

598


write a program to convert a expression in polish notation(postfix) to inline(normal) something like make 723+* (2+3) x 7 (not sure) just check out its mainly printing expression in postfix form to infix.

3503


What is a constant?

636


Using functions, write a program that multiplies two arrays. Use the following functions: - Function ReadArray - Function MultiplyArrays - Function DisplayArrays

1893


How do you declare a variable that will hold string values?

671


Differentiate fundamental data types and derived data types in C.

619


In the DOS enveronment, normal RAM that resides beyond the 1mb mark. a) expanded memory b) swapped memory c) Extended memory d) none

721