Binary tree traversal in order , Report errors NameError: name 'PreOrder' is not defined
# Binary chain node class class BTNode: def __init__(self, d=None): self.data = d self.lchild = None self.rchild = None# Binary tree class class BTree: def __init__(self): # Create a binary tree self.b = None def SetRoot(self, r): self.b = rdef PreOreder(bt): # The first sequence traversal _PreOrder(bt.b)def _PreOrder(b): if b != None: print(b.data,end='') _PreOrder(b.lchild) _PreOrder(b.rchild)if __name__ == '__main__': # Create binary chain b = BTNode('A') p1 = BTNode('B') p2 = BTNode('C') p3 = BTNode('D') p4 = BTNode('E') p5 = BTNode('F') p6 = BTNode('G') b.lchild = p1 b.rchild = p2 p1.lchild = p3 p3.rchild = p6 p2.lchild = p4 p2.rchild = p5 # Create a binary tree object bt = BTree() bt.SetRoot(b) # The first sequence traversal PreOrder(bt)