(树)-二叉树前中后遍历
def inorder(root):
'''
中序遍历
:param root:
:return:
'''
if root != None:
inorder(root.left)
print('[%d]' % root.data, end=' ')
inorder(root.right)
def postorder(root):
'''
后序遍历
:param root:
:return:
'''
if root != None:
inorder(root.left)
inorder(root.right)
print('[%d]' % root.data, end=' ')
def preorder(root):
'''
前序遍历
:param root:
:return:
'''
if root != None:
print('[%d]' % root.data, end=' ')
inorder(root.left)
inorder(root.right)