多叉树遍历
来源:互联网 发布:css3 知乎 编辑:程序博客网 时间:2024/06/10 02:10
import nltk.tree as tree# 递归遍历def test(t): if isinstance(t, str): print t else: for i in range(len(t)): test(t[len(t)-i-1])# 非递归遍历def test_2(t): stack = [] stack.append(t) current = "" while stack: current = stack.pop() if isinstance(current, tree.Tree): for i in range(len(current)): stack.append(current[i]) elif isinstance(current, str): # print "[输出] ",current print currentif __name__ == "__main__": C = tree.Tree("C", ["E", "F"]) B = tree.Tree("B", [C, "D"]) H = tree.Tree("H", ["M", "N"]) A = tree.Tree("A", ["G", H]) root = tree.Tree("Root", [A, B]) print root[0] print root.height() print len(root) print type(root) test(root) test_2(root) root.draw()
0 0
- 多叉树遍历
- 多叉树遍历
- 多叉树的递归遍历和堆栈遍历
- 多叉树的层次遍历
- java 多叉树遍历
- java多叉树遍历
- 多叉树的遍历
- 树---多叉树的遍历
- 多叉树的深度遍历
- 多叉树遍历-文件夹
- 多叉树的递归遍历和堆栈遍历【多叉树的前序遍历及后续遍历】
- 遍历
- 遍历
- 遍历
- 遍历
- 遍历
- 遍历
- 遍历
- 关于LLVM,这些东西你必须要知道!
- 一键分享之新浪微博
- ionic添加cordova插件-PinDialog
- 邮件营销在大数据下该怎么运作?
- 逆讯图驴企业版,这一次颜值更高
- 多叉树遍历
- shell使用
- QT样式翻译
- LintCode46主元素
- 欢迎使用CSDN-markdown编辑器
- html5新增标签
- 装饰模式
- 笔记3~CSMA/CA协议
- Java初学者的30个常见问题