public void PreOrder()
{
Stack stack = new Stack();
if (this.Root == null)
{
Console.WriteLine("노드가 없습니다.");
}
else
{
Node temp = this.Root;
while(true)
{
if (temp != null)
{
Console.Write("{0} ", temp.Data);
stack.Push(temp);
if (temp.Left == null)
{
temp = stack.Pop().Right;
while (stack.Count() > 0 && temp == null)
{
temp = stack.Pop().Right;
}
}
else
{
temp = temp.Left;
}
}
else
{
Console.WriteLine();
return;
}
}
}
}
'자료구조' 카테고리의 다른 글
이진트리 PreOrder 재귀구현 (0) | 2021.12.28 |
---|---|
이진트리 LevelOrder + AddChild (0) | 2021.12.28 |
LCRS트리 PreOrder 재귀구현 (0) | 2021.12.28 |
사향트리 PreOrder (0) | 2021.12.28 |
사향트리 LeftSkewedTree (0) | 2021.12.28 |