特别说明
树往往要比python内置的dict类慢一些,但是它中的所有数据都是按照某个关键词进行排序的,故在某些情况下是必须使用的。
python中的二叉树模块内容:
- BinaryTree:非平衡二叉树
- AVLTree:平衡的AVL树
- RBTree:平衡的红黑树
使用例子:
from bintrees import RBTree
btree = RBTree()
btree.insert('111',"first")
btree.insert('333', "second")
btree.insert('2222', "thirdly")
print btree
# result : RBTree({'111': 'first', '2222': 'thirdly', '333': 'second'})
注意:
其他API看源码或官方文档: https://github.com/mozman/bintrees