前序遍历结果:1, 2, 4, 5, 8, 9, 11, 3, 6, 7, 10
中序遍历结果:4, 2, 8, 5, 11, 9, 1, 6, 3, 10, 7
后序遍历结果:4, 8, 11, 9, 5, 2, 6, 10, 7, 3, 1
根节点表示:
class Node(object):
def __init__(self, value=None, left=None, right=None):
self.value = value
self.left = left
self.right = right
if __name__ == "__main__":
tree = Node(1, Node(2, Node(4), Node(5, Node(8), Node(9, left=Node(11)))), Node(3, Node(6), Node(7, left=Node(10))))
1、深度优先遍历
1.1 递归