public void LevelOrder()
{
Queue q = new Queue();
q.Enqueue(this.Root);
Node temp;
if (this.Root == null)
{
Console.WriteLine("노드가 없습니다.");
}
else
{
while (q.Count() != 0)
{
temp = q.Dequeue();
Console.Write("{0} ", temp.Data);
if (temp.Left != null)
{
q.Enqueue(temp.Left);
if (temp.Left.Right != null)
{
q.Enqueue(temp.Left.Right);
}
}
}
}
}
class App
{
//생성자
public App()
{
BinaryTree bt = new BinaryTree();
Node root = bt.AddChild(bt.Root, "A");
Node b = bt.AddChild(root, "B");
Node c = bt.AddChild(root, "C");
Node d = bt.AddChild(c, "D");
bt.AddChild(c, "E");
bt.AddChild(b, "F");
Node g = bt.AddChild(b, "G");
bt.AddChild(d, "H");
bt.AddChild(d, "I");
bt.AddChild(g, "J");
bt.AddChild(g, "K");
Console.WriteLine();
bt.LevelOrder();
}
}
'자료구조' 카테고리의 다른 글
사향트리 PreOrder (0) | 2021.12.28 |
---|---|
사향트리 LeftSkewedTree (0) | 2021.12.28 |
일반트리 (0) | 2021.12.28 |
LCRS트리 (0) | 2021.12.28 |
트리 LCRS Expression (0) | 2021.12.28 |