from collections import deque
def level(root,lv):
queue=deque()
queue.append(root)
while len(queue)>0:
node=queue.popleft()
lv.append(node.data)
if node.lchild!=None:
queue.append(node.lchild)
if node.rchild!=None:
queue.append(node.rchild)
return lv
class Tree:
def creat(self,post,mid):
if post==[] or mid==[]:
return
root=Node(post[-1])
i=mid.index(post[-1])
root.lchild=self.creat(post[:i],mid[:i])
root.rchild=self.creat(post[i:len(post)-1],mid[i+1:])
return root
class Node:
def __init__(self,data):
self.data=data
self.lchild=None
self.rchild=None
n=int(input())
post=input().split()
mid=input().split()
an=Tree()
b=an.creat(post,mid)
print(*level(b,[]))
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)