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 is strcmp in c?
What is the scope of static variable in c?
How can you increase the size of a statically allocated array?
What does 4d mean in c?
What is build process in c?
Which of the following operators is incorrect and why? ( >=, <=, <>, ==)
which of the following shows the correct hierarchy of arithmetic operations in C a) (), **, * or/,+ or - b) (),**,*,/,+,- c) (),**,/,*,+,- d) (),/ or *,- or +
in iso what are the common technological language?
What is the difference between mpi and openmp?
Why does the call char scanf work?
Explain how can you determine the size of an allocated portion of memory?
In this problem you are to write a program that will cut some number of prime numbers from the list of prime numbers between 1 and N.Your program will read in a number N; determine the list of prime numbers between 1 and N; and print the C*2 prime numbers from the center of the list if there are an even number of prime numbers or (C*2)-1 prime numbers from the center of the list if there are an odd number of prime numbers in the list.
What is #include stdlib h?
When should the volatile modifier be used?
What are qualifiers?