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
how to count no of words,characters,lines in a paragraph.
Write a program to swap two numbers without using third variable in c?
Can you explain the four storage classes in C?
Why we use int main and void main?
How many types of sorting are there in c?
How many levels deep can include files be nested?
How will you declare an array of three function pointers where each function receives two ints and returns a float?
What is const and volatile in c?
Do pointers need to be initialized?
What kind of structure is a house?
How can I ensure that integer arithmetic doesnt overflow?
Differentiate between calloc and malloc.
What is the difference between declaring a variable by constant keyword and #define ing that variable?
How many keywords are there in c?
hi, which software companys will take,if d candidate's % is jst 55%?