码迷,mamicode.com
首页 > 其他好文 > 详细

2019.9.26-二叉树的实现代码

时间:2019-09-27 01:28:20      阅读:72      评论:0      收藏:0      [点我收藏+]

标签:alt   none   object   mic   png   nod   child   app   elf   

# 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-二叉树的实现代码

标签:alt   none   object   mic   png   nod   child   app   elf   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!