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
If I have a char * variable pointing to the name of a function ..
What are the header files used in c language?
What are the key features in c programming language?
Why do we need arrays in c?
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
difference between object file and executable file
What is the maximum length of an identifier?
In which header file is the null macro defined?
How can you increase the allowable number of simultaneously open files?
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.
What is a constant?
Using functions, write a program that multiplies two arrays. Use the following functions: - Function ReadArray - Function MultiplyArrays - Function DisplayArrays
How do you declare a variable that will hold string values?
Differentiate fundamental data types and derived data types in C.
In the DOS enveronment, normal RAM that resides beyond the 1mb mark. a) expanded memory b) swapped memory c) Extended memory d) none