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

how to count no of words,characters,lines in a paragraph.

4430


Write a program to swap two numbers without using third variable in c?

1132


Can you explain the four storage classes in C?

1125


Why we use int main and void main?

1081


How many types of sorting are there in c?

1061


How many levels deep can include files be nested?

1142


How will you declare an array of three function pointers where each function receives two ints and returns a float?

1368


What is const and volatile in c?

1050


Do pointers need to be initialized?

1086


What kind of structure is a house?

1048


How can I ensure that integer arithmetic doesnt overflow?

1173


Differentiate between calloc and malloc.

1273


What is the difference between declaring a variable by constant keyword and #define ing that variable?

3371


How many keywords are there in c?

1078


hi, which software companys will take,if d candidate's % is jst 55%?

2093