from collections import deque
class BiTNode:
def __init__(self):
self.data = None
self.lchild = None
self.rchild = None
def reverseTree(root):
if root == None:
return None
reverseTree(root.lchild)
reverseTree(root.rchild)
tmp = root.lchild
root.lchild = root.rchild
root.rchild = tmp
def arraytotree(arr, start, end):
if end >= start:
root = BiTNode()
mid = (start + end + 1)//2
root.data = arr[mid]
root.lchild = arraytotree(arr, start, mid-1)
root.rchild = arraytotree(arr, mid+1, end)
else:
root = None
return root
def printTreeLayer(root):
if root == None:
return
queue = deque()
queue.append(root)
while len(queue)>0 :
p = queue.popleft()
print(p.data,end=' ')
if p.lchild != None :
queue.a
Python:如何对二叉树进行镜像翻转
最新推荐文章于 2022-08-10 11:36:30 发布