标签:style module sel 二叉树 order python 前序遍历 none bsp
class BinaryTree: def __init__(self,value): self._left=None self._right=None self._data=value def insertLeftChild(self,value): #创建左子树 if self._left: print(‘left child tree already exists.‘) else: self._left=BinaryTree(value) return self._left def insertRightChild(self,value): #创建右子树 if self._right: print(‘right child tree already exists.‘) else: self._right=BinaryTree(value) return self._right def show(self): print(self._data) def preOrder(self): #前序遍历(根左右) print(self._data) if self._left: self._left.preOrder() if self._right: self._right.preOrder() def postOrder(self): #后序遍历(左右根) if self._left: self._left.postOrder() if self._right: self._right.postOrder() print(self._data) def inOrder(self): #中序遍历(左根右) if self._left: self._left.inOrder() print(self._data) if self._right: self._right.inOrder() if __name__==‘__main__‘: print(‘Please use me as a module.‘)
标签:style module sel 二叉树 order python 前序遍历 none bsp
原文地址:https://www.cnblogs.com/python666666/p/9958381.html