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
The program will first compute the tax you owe based on your income. User is prompted to enter income. Program will compute the total amount of tax owed based on the following: Income Tax 0 - $45,000 = 0.15 x income $45,001 - $90,000 = 6750 + 0.20 x (income – 45000) $90,001 - $140,000 = 15750 + 0.26 x (income – 90000) $140,001 - $200,000 = 28750 + 0.29 x (income – 140000) Greater than $200,000 = 46150 + 0.33 x (income – 200000) Dollar amounts should be in dollars and cents (float point numbers with two decimals shown). Tax is displayed on the screen.
any limit on the number of functions that might be present in a C program a) max 35 functions b) max 50 functions c) no limit d) none of the above
What is the purpose of 'register' keyword?
Write a client and server program in C language using UDP, where client program interact with the Server as given below: i) The client begins by sending a request to send a string of 8 characters or series of 7 numbers, the server sends back a characters or numbers as per the request of the client. ii) In case of series of 7 numbers: The client sends a multiplication of numbers, to the server. iii) In case of a string of 8 characters: The client sends a reverse order of string to the server.. iv) Server will send an acknowledgment to the client after receiving the correct answer
What are global variables and how do you declare them?
Why we use stdio h in c?
How will you write a code for accessing the length of an array without assigning it to another variable?
Write a program to implement queue.
What are runtime error?
Explain how do you use a pointer to a function?
What is clrscr ()?
why do some people write if(0 == x) instead of if(x == 0)?
What is meant by keywords in c?
What is the scope of static variables in c language?
Write a function stroverlap that takes (at least) two strings, and concatenates them, but does not duplicate any overlap. You only need to worry about overlaps between the end of the first string and the beginning of the second string. Examples: batman, manonthemoon = batmanonthemoon batmmamaman, mamamanonthemoon = batmmamamanonthemoon bat, man = batman batman, batman = batman batman, menonthemoon = batmanmenonthemoon