Python实现二叉树
来源:互联网 发布:文玩淘宝店 编辑:程序博客网 时间:2024/06/05 15:17
class Btree: root = None def __init__(self, data=None): root = self.Node(data) self.root = root def append(self,data): node = self.Node(data) if self.root is None: self.root=node else: self.root.append(node) class Node: data = None left = None right = None def __init__(self, data=None): self.data=data def append(self,node): #追加函数 if self.data > node.data: if self.left is None: self.left=node else: self.left.append(node) else: if self.right is None: self.right=node else: self.right.append(node) def zPrint(self): #中序输出 if self.left is not None: self.left.zPrint() print(self.data) if self.right is not None: self.right.zPrint def zPrint(self): self.root.zPrint()
添加数据并中序输出
btree=Btree(5)btree.append(3)btree.append(7)#....*nbtree.zPrint()
阅读全文
0 0
- Python实现二叉树
- python实现二叉树
- python实现二叉树
- Python实现二叉树
- Python实现二叉树
- Python实现二叉树
- python实现二叉树
- Python实现二叉树
- 二叉查找树:Python实现
- python实现二叉查找树
- 二叉查找树python实现
- python实现二叉树遍历
- python实现二叉查找树
- 二叉树的实现 Python
- 二叉查找树python实现
- 二叉搜索树 python实现
- python实现二叉树排序
- python实现二叉树,以及二叉树的遍历
- opencv之分水岭算法分割及图像修补
- Leetcode-401. Binary Watch
- JAVA 对象序列化(一)——Serializable
- xml解析系列(二)——用Marshaller和Unmarshaller解析xml
- 英语语法
- Python实现二叉树
- QQ应用自动登录最小化功能
- android 目录
- oracle学习之:CONNECT BY层次化查询
- NIO Channel
- 初学python--认识装饰器
- 图像处理算法工程师面试题
- CSS学习笔记-2
- 欢迎使用CSDN-markdown编辑器