Python      python3使用pybst可视化完全二叉树   
文章目录  [隐藏]

PyBST在Python2中实现了二进制树、AVL树、Splay树和红黑树。此外,PyBST还提供了一个模块,用于使用networkx和matplotlib绘制这些树。
https://pypi.org/project/pybst/
https://github.com/TylerSandman/py-bst

1.pybst的若干准备

在python3中使用,需要做必要的修改。

首先,修改文件 "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pybst/draw.py", 21行。
import bstree as bst 改为import pybst.bstree as bst,或直接 注释掉。
然后,修改文件 "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pybst/bstree.py",196行。
if not isinstance(key,(int,long, float)): 里的long删除,因为python3中已经没有long类型,可以查找其它有long判断的地方删除。
最后,参考 https://www.cnblogs.com/harrychinese/p/binary_tree_visualization.html 在bstree.py中,为BSTree类,添加3个方法:

2.可视化示例

pybst的相关方法:

示例一个元素为1-7的可视化:
pybst

- end

承接App定制、企业web站点、办公系统软件 设计开发,外包项目,毕设