用python自定义树,先定义节点,然后在把节点合成树。
class TreeNode(object):
def __init__(self,root,left=None,right=None):
self.root = root
self.left = left
self.right = right
A = TreeNode('A')
B = TreeNode('B')
C = TreeNode('C')
D = TreeNode('D')
A.left = B
A.right = C
B.right = D
A.root = 10
B.root = 20
C.root = 30
print A
print A.root,B.root,C.root