0%
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| ''' a . b . . c d . . e f . g '''
class Node(): def __init__(self,data=None,L=None,R=None): self.data = data self.L = L self.R = R def Creat_tree(H,p=Node()): if H[0] == '#': H.pop(0) return None else: p.data = H.pop(0) p.L = Creat_tree(H,Node()) p.R = Creat_tree(H,Node()) return p
def inordertraversal(BT,list_=[]): if BT: inordertraversal(BT.L,list_) list_.append(BT.data) inordertraversal(BT.R,list_) return (list_)
H = list('abc##de#g##f###') tree = Creat_tree(H) result = inordertraversal(tree) print(result)
|