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


Please Help Members By Posting Answers For Below Questions

How would you obtain the current time and difference between two times?

719


How to find a missed value, if you want to store 100 values in a 99 sized array?

803


What is getch () for?

667


What are the rules for identifiers in c?

579


What is void c?

558






Difference between pass by reference and pass by value?

647


HOW TO SOLVE A NUMERICAL OF LRU IN OS ??????

2259


void main(int n) { if(n==0) return; main(--n); printf("%d ",n); getch(); } how it work and what will be its output...............it any one know ans plz reply

2208


Write a program of advanced Fibonacci series.

700


Explain how does free() know explain how much memory to release?

566


What is optimization in c?

560


I completed my B.tech (IT). Actually I want to develop virtual object that which will change software technology in the future. To develop virtual object what course I have to take. can I any professor to help me.

1731


Explain union.

629


Why isn't any of this standardized in c? Any real program has to do some of these things.

615


What is the heap?

676