2019.9.26-二叉树的实现代码

# coding:utf-8

class Node(object):
""""""
def __init__(self, item):
self.elem = item
self,lchild = None
self.rchild = None

class Tree(object):
"""二叉樹"""
def __init__(self):
self,root = None

def add(self, item):
node = Node(item)
if self.roor is Node:
self.root = node
return
queue = [self.root]
while queue:
cur_node = queue.pop(0)
if cur_node.lchild is None:
cur_node.lchild = node
return
else:
queue.append(cur_node.lchild)
if cur_node.rchild is None:
cur_node.rchild = node
return
else:
queue.append(cur_node.rchild)

tree = Tree()

猜你喜欢

转载自www.cnblogs.com/lishuide/p/11595137.html