20 前序中序求后序

优质
小牛编辑
138浏览
2023-12-01

推荐: http://blog.csdn.net/hinyunsin/article/details/6315502

def rebuild(pre, center):
  if not pre:
    return
  cur = Node(pre[0])
  index = center.index(pre[0])
  cur.left = rebuild(pre[1:index + 1], center[:index])
  cur.right = rebuild(pre[index + 1:], center[index + 1:])
  return cur

def deep(root):
  if not root:
    return
  deep(root.left)
  deep(root.right)
  print root.data