1. 实现二叉树
def BinaryTree(r):
return [r,[],[]]
def InsertLeft(root,newBranch):
t=root.pop(1)
if len(t)>1: #左子节点的列表不为空
root.insert(1,[newBranch,t,[]])
else:
root.insert(1,[newBranch,[],[]])
return root
def InsertRight(root,newBranch):
t=root.pop(2)
if len(t)>1:
root.insert(2,[newBranch,[],t])
else:
root.insert(2,[newBranch,[],[]