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
Write a code to generate divisors of an integer?
What is the ANSI C Standard?
What is the use of typedef in structure in c?
Describe the modifier in c?
What is malloc return c?
Why c is called procedure oriented language?
In c programming write a program that will print 10 multiples of 3 except 15,18,21 using looping
What is the difference between a free-standing and a hosted environment?
What are the different file extensions involved when programming in C?
What are the two forms of #include directive?
Why c is known as a mother language?
Can the curly brackets { } be used to enclose a single line of code?
Explain how can I convert a string to a number?
How can you tell whether a program was compiled using c versus c++?
What is the process to create increment and decrement stamen in c?