How would you print out the data in a binary tree, level by
level, starting at the top?
Answer Posted / ds
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 ? | 34 Yes | 7 No |
Post New Answer View All Answers
What are header files and what are its uses in C programming?
The __________ attribute is used to announce variables based on definitions of columns in a table?
What are the advantage of c language?
What are the basic data types associated with c?
Do you know the difference between malloc() and calloc() function?
What is getch?
#include main() { char s[] = "Bouquets and Brickbats"; printf(" %c, ",*(&s[2])); printf("%s, ",s+5); printf(" %s",s); printf(" %c",*(s+2)); }
main() { struct s1 { char *str; struct s1 *ptr; }; static struct s1 arr[] = { {"Hyderabad",arr+1}, {"Bangalore",arr+2}, {"Delhi",arr} }; struct s1 *p[3]; int i; < BR> for(i=0;i<=2;i++) p[i] = arr[i].ptr; printf("%s ",(*p)->str); printf("%s ",(++*p)->str); printf("%s ",((*p)++)->str); }
Is c procedural or object oriented?
Explain what will be the outcome of the following conditional statement if the value of variable s is 10?
A collection of functions,calls,subroutines or other data a) library b) header files c) set of files d) textfiles
What is %lu in c?
How important is structure in life?
Write a code to determine the total number of stops an elevator would take to serve N number of people.
What is double pointer in c?