(树)-二叉树前中后遍历

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)

 

posted @ 2019-02-16 19:51  jj千寻  阅读(43)  评论(0编辑  收藏  举报