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
Why do we use int main instead of void main in c?
What is meant by errors and debugging?
Difference between Function to pointer and pointer to function
Can true be a variable name in c?
how can i access hard disk address(physical address)? are we access hard disk by using far,near or huge pointer? if yes then please explain.....
How to implement a packet in C
any limit on the number of functions that might be present in a C program a) max 35 functions b) max 50 functions c) no limit d) none of the above
What is the modulus operator?
In C programming, what command or code can be used to determine if a number of odd or even?
What is abstract data structure in c?
Write a program to check whether a number is prime or not using c?
What is the role of && operator in a program code?
What should malloc() do?
What is const keyword in c?
What is the use of parallelize in spark?