ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   SiteMap shows list of All Categories in this site.
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C
 
 


 

 
 C interview questions  C Interview Questions
 C++ interview questions  C++ Interview Questions
 VC++ interview questions  VC++ Interview Questions
 Delphi interview questions  Delphi Interview Questions
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions
Question
How would you print out the data in a binary tree, level by
level, starting at the top?
 Question Submitted By :: Gvsk05
I also faced this Question!!     Rank Answer Posted By  
 
  Re: How would you print out the data in a binary tree, level by level, starting at the top?
Answer
# 1
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 ?    1 Yes 12 No
Hardik
 
  Re: How would you print out the data in a binary tree, level by level, starting at the top?
Answer
# 2
By using inorder,preorder,postorder.the data may print as 
LDR,DLR,LRD.this only the chance to print data in a bionary 
tree.
 
Is This Answer Correct ?    0 Yes 6 No
Sridhar
 
 
 
  Re: How would you print out the data in a binary tree, level by level, starting at the top?
Answer
# 3
Use a queue to achieve this.
1. push root to queue
2. if root!=NULL, pop root and print data.
3. visit left child and right child of root and push them to
queue
4. pop leftchild from queue , print data, push left and
right child.
5. pop rightchild from queue, print data, push left and
right child.
6. carry on till queue is empty.
 
Is This Answer Correct ?    5 Yes 4 No
Ds
 
  Re: How would you print out the data in a binary tree, level by level, starting at the top?
Answer
# 4
Use   Breadth First search  algorithm. This is using  queue
as the data structure .
 
Is This Answer Correct ?    3 Yes 0 No
Janraj Cj
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
How can I make a program in c to print 'Hello' without using semicolon in the code? C-DAC5
What is the most efficient way to count the number of bits which are set in a value?  3
void main() {int a[5],i,b=16; for(i=0;i<5;i++) a[i]=2*i; f(a,5,b); for(i=0;i<5;i++) printf("\n %d",a[i]); printf("\n %d",b); } f(int *x,int n,int y) { int i; for(i=0;i<n;i++) *(x+i)+=2; y=y+2; }wat r the errors in the prg.and improvise the prg to get o/p.?  2
How can I convert integers to binary or hexadecimal?  2
Why doesn't C have nested functions?  2
int i; i=2; i++; if(i=4) { printf(i=4); } else { printf(i=3); } output of the program ? Mascot9
To find whether a number is even or odd without using any conditional operator?? IBM4
WHAT IS THE DIFFERANCE BITWIN GETS();AND SCANF();  2
pgm to reverse string using arrays i.e god is love becomes love is god) (assumption:only space is used for seperation of words) no addtional memory used.i.e no temporary arrays can used. Persistent4
convert 12345 to 54321 withoutusing strig  3
wt is d full form of c Wipro1
how many times of error occur in C  7
write a program in c language for the multiplication of two matrices using pointers? Ignou5
write a string copy function routine?  1
write the program for maximum of the following numbers? 122,198,290,71,143,325,98  4
What does extern mean in a function declaration?  2
write a c program to check weather a particluar bit is set or not? IBM4
How can I call a function, given its name as a string? ABC-Telecom2
what does exit() do? Cadence3
Here is alphabets : abcdefgh 1) how to reverse. as hgfedcba 2) after reversal, how to group them in a pair hg fe dc ba.  2
 
For more C Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com