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       Ask Questions on ANYTHING, that arise in your Daily Life at     FORUM9.COM
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 5 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 2 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 ?    2 Yes 0 No
Ds
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
How can I set an array's size at run time?  7
what is the hexidecimal number of 4100? Google13
pgm to find number of words starting with capital letters in a file(additional memory usage not allowed)(if a word starting with capital also next letter in word is capital cann't be counted twice) Subex1
N O S I E R + A S T R A L ---------------- 7 2 5 6 1 3 Honeywell1
What is structure packing ? HP1
declare afunction pointer to int printf(char *)? HCL1
Give the output for the following program. #define STYLE1 char main() { typedef char STYLE2; STYLE1 x; STYLE2 y; clrscr(); x=255; y=255; printf("%d %d\n",x,y); } ADITI1
can we access one file to one directory?  1
two variables are added answer is stored on not for third variable how it is possible?  2
what about "char *(*(*a[])())();" Oracle2
what are the uses of structure? HCL3
what is the use of getch() function in C program.. difference b/w getch() and getche()?? Wipro10
Write a program to generate prime factors of a given integer?  1
How the processor registers can be used in C ? HP4
What does a run-time "null pointer assignment" error mean?  2
main() { int i=1; while (i<=5) { printf("%d",i); if (i>2) goto here; i++; } } fun() { here: printf("PP"); } ME3
What is an volatile variable? HP6
24.what is a void pointer? 25.why arithmetic operation can’t be performed on a void pointer? 26.differentiate between const char *a; char *const a; and char const *a; 27.compare array with pointer? 28.what is a NULL pointer? 29.what does ‘segmentation violation’ mean? 30.what does ‘Bus Error’ mean? 31.Define function pointers? 32.How do you initialize function pointers? Give an example? 33.where can function pointers be used?  1
How do I declare a pointer to an array?  5
difference between memcpy and strcpy  1
 
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