赞
踩
self.element = element
self.l_child = l_child
self.r_child = r_child
class Tree(object):
“”“树类”""
def init(self):
self.root = Node()
self.queue = []
def add_node(self, element):
“”“为树添加节点”""
node = Node(element)
if self.root.element == -1:
self.root = node
self.queue.append(self.root)
else:
tree_node = self.queue[0]
if tree_node.l_child is None:
tree_node.l_child = node
self.queue.append(tree_node.l_child)
else:
tree_node.r_child = node
self.queue.append(tree_node.r_child)
self.queue.pop(0)
def front_recursion(self, root):
“”“利用递归实现树的前序遍历”""
if root is
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。