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
What does 2n 4c mean?
write a program to copy the string using switch case?
When should the register modifier be used? Does it really help?
What is an example of structure?
What is function prototype?
What does c mean in standard form?
When is a void pointer used?
A program is required to print your biographic information including: Names, gender, student Number, Cell Number, line of study and your residential address.
Should a function contain a return statement if it does not return a value?
Explain how can you restore a redirected standard stream?
What are predefined functions in c?
What does %2f mean in c?
largest Of three Number using without if condition?
Why does everyone say not to use gets?
Explain how can a program be made to print the name of a source file where an error occurs?