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 %d do in c?
What are high level languages like C and FORTRAN also known as?
which of the following is allowed in a "C" arithematic instruction a) [] b) {} c) () d) none of the above
What is typedef struct in c?
Describe the steps to insert data into a singly linked list.
What does %p mean?
How a string is stored in c?
How important is structure in life?
How can I read a binary data file properly?
C language questions for civil engineering
What are the types of arrays in c?
"C" language developed by "Dennis Ritchie" at AT & T. his remarks are a) too general, too abstract b) could deal with only specific problems c) lost generality of BCPL and B restored d) no remarks
What is NULL pointer?
exit () is used to a) exit () terminates the execution of the program itself b) exit () terminates the execution of the loop c) exit () terminates the execution of the block d) none of the above
What are the features of c languages?