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

What is the best way of making my program efficient?

561


What are the two forms of #include directive?

640


What is the difference between new and malloc functions?

574


Are pointers integers in c?

606


Which built-in library function can be used to match a patter from the string?

739






Explain how can I convert a string to a number?

643


Why do we use header files in c?

573


How can I find the modification date and time of a file?

598


What is the collection of communication lines and routers called?

608


What is boolean in c?

603


Is it valid to address one element beyond the end of an array?

669


What is the acronym for ansi?

626


Write a program to reverse a string.

631


How will you divide two numbers in a MACRO?

708


a program that can input number of records and can view it again the record

1478