Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

Write a code to generate divisors of an integer?

1062


What is the ANSI C Standard?

1268


What is the use of typedef in structure in c?

966


Describe the modifier in c?

1100


What is malloc return c?

1018


Why c is called procedure oriented language?

1038


In c programming write a program that will print 10 multiples of 3 except 15,18,21 using looping

1508


What is the difference between a free-standing and a hosted environment?

1142


What are the different file extensions involved when programming in C?

1251


What are the two forms of #include directive?

1160


Why c is known as a mother language?

1079


Can the curly brackets { } be used to enclose a single line of code?

1163


Explain how can I convert a string to a number?

1090


How can you tell whether a program was compiled using c versus c++?

1099


What is the process to create increment and decrement stamen in c?

1056