首页 > 其他 > 详细

2019.9.26-二叉树的实现代码

时间:2019-09-27 00:50:10      阅读:83      评论:0      收藏:0      [点我收藏+]

# 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()

技术分享图片

 

 

技术分享图片

 

2019.9.26-二叉树的实现代码

原文:https://www.cnblogs.com/lishuide/p/11595137.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!