# 전회 순회(Preorder), 중위 순회(Inorder), 후위 순회(Postorder)
# DFS 를 구현 하는 방법
# Stack or Recursion
# 접근과 방문은 다르다.
class Node:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
class BinaryTree:
def __init__(self):
self.root = None
def preorder(root):
if root is None:
return
print(root.value, end=' ')
preorder(root.left)
preorder(root.right)
def inorder(root):
if root is None:
return
inorder(root.left)
print(root.value, end=' ')
inorder(root.right)
def postorder(root):
if root is None:
return
postorder(root.left)
postorder(root.right)
print(root.value, end=' ')
bt = BinaryTree()
bt.root = Node(value=1)
bt.root.left = Node(value=2)
bt.root.right = Node(value=3)
bt.root.left.left = Node(value=4)
bt.root.left.right = Node(value=5)
bt.root.right.left = Node(value=6)
bt.root.right.right = Node(value=7)
preorder(bt.root)
print('\n')
inorder(bt.root)
print('\n')
postorder(bt.root)