python二叉树遍历方法及其求二叉树高度
新人求助
先上代码
代码:
class BinaryTreeNode(object):
def __init__(self):
self.data='#'
self.leftchild=None
self.rightchild=None
class TreeState(object):
def __init__(self,BinaryTreeNode,VisitedFlag):
self.BinaryTreeNode = BinaryTreeNode
self.VisitedFlag = VisitedFlag
class BinaryTree(object):
def Createtree(self,Root):
data=input('->')
if data=='#':
Root=None
else:
Root.data=data
Root.leftchild=BinaryTreeNode()
self.Createtree(Root.leftchild)
Root.rightchild=BinaryTreeNode()
self.Createtree(Root.rightchild)
###################################
#先序遍历递归算法
###################################
def PreOrder(self,Root):
if Root is not None:
self.VisitBinaryTreeNode(Root)<