How would you print out the data in a binary tree, level by
level, starting at the top?

Answer Posted / sucharit

This is the C# version

private void PrintLevelOrder(BinaryTreeNode node)
{
// Do a level Order Traversal

Queue<BinaryTreeNode> queue = new
Queue<BinaryTreeNode>();

queue.Enqueue(node);

while (queue.Count != 0)
{

Console.WriteLine((node = queue.Dequeue
() as BinaryTreeNode).IntValue.ToString());

if (node.Left !=null)
queue.Enqueue(node.Left as
BinaryTreeNode);
if (node.Right!=null)
queue.Enqueue(node.Right as
BinaryTreeNode);


}


}

Is This Answer Correct ?    3 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What does 2n 4c mean?

710


write a program to copy the string using switch case?

2395


When should the register modifier be used? Does it really help?

607


What is an example of structure?

585


What is function prototype?

607






What does c mean in standard form?

593


When is a void pointer used?

672


A program is required to print your biographic information including: Names, gender, student Number, Cell Number, line of study and your residential address.

1246


Should a function contain a return statement if it does not return a value?

592


Explain how can you restore a redirected standard stream?

587


What are predefined functions in c?

560


What does %2f mean in c?

672


largest Of three Number using without if condition?

1003


Why does everyone say not to use gets?

603


Explain how can a program be made to print the name of a source file where an error occurs?

682