Tree Representation Implementation & Traversal
http://blog.csdn.net/bone_ace/article/details/46718683
Tree implemention using list
def BinaryTree(r):
return [r, [], []] def insertLeft(root, newBranch):
t = root.pop(1)
if len(t) > 1:
# if the left child has node t, then we push it down
root.insert(1, [newBranch, t, []])
else:
root.insert(1, [newBranch, [], []])
return root def insertRight(root, newBranch):
t = root.pop(2)
if len(t) > 1:
root.insert(2, [newBranch, [], t])
else:
root.insert(2, [newBranch, [], []])
return root def getRootVal(root):
return root[0] def setRootVal(root, newVal):
root[0] = newVal def getLeftChild(root):
return root[1] def getRightChild(root):
return root[2]
Tree Representation Implementation & Traversal的更多相关文章
- [LeetCode] Binary Tree Vertical Order Traversal 二叉树的竖直遍历
Given a binary tree, return the vertical order traversal of its nodes' values. (ie, from top to bott ...
- [LeetCode] Binary Tree Level Order Traversal II 二叉树层序遍历之二
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left ...
- [LeetCode] Binary Tree Level Order Traversal 二叉树层序遍历
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, ...
- LeetCode Binary Tree Vertical Order Traversal
原题链接在这里:https://leetcode.com/problems/binary-tree-vertical-order-traversal/ 题目: Given a binary tree, ...
- 【leetcode】Binary Tree Level Order Traversal I & II
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, ...
- LeetCode之Binary Tree Level Order Traversal 层序遍历二叉树
Binary Tree Level Order Traversal 题目描述: Given a binary tree, return the level order traversal of its ...
- 35. Binary Tree Level Order Traversal && Binary Tree Level Order Traversal II
Binary Tree Level Order Traversal OJ: https://oj.leetcode.com/problems/binary-tree-level-order-trave ...
- LeetCode:Binary Tree Level Order Traversal I II
LeetCode:Binary Tree Level Order Traversal Given a binary tree, return the level order traversal of ...
- 【Binary Tree Level Order Traversal II 】cpp
题目: Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from ...
随机推荐
- shell随笔
一, case的详细用法: 参考文章(http://blog.csdn.net/dreamtdp/article/details/8048720) 语句实例:由用户从键盘输入一个字符,并判断该字符 ...
- Bootstrap Table 中文文档(完整翻译版)
表格参数: 名称 标签 类型 默认 描述 - data-toggle String ‘table’ 不用写 JavaScript 直接启用表格. classes data-classes String ...
- springboot web项目的单元测试
不废话,直接上代码. //// SpringJUnit支持,由此引入Spring-Test框架支持! @RunWith(SpringJUnit4ClassRunner.class) //// 指定我们 ...
- Unresolved external CheckAutoResult
// [Linker Error]Unresolved external 'System::__linkproc__ __fastcall CheckAutoResult() ' ...
- 无法读取用户配置文件,系统自动建立Temp临时用户
chkdsk/f 删除用户目录下的 ntuser.dat.LOG 文件,重新登陆即可. 对于新建用户的情况: 一.Default User文件夹不完整或者被删除了,导致系统无法复制新的一份.这种情况的 ...
- 可视化库-seaborn-回归分析绘图(第五天)
1. sns.regplot() 和 sns.lmplot() 绘制回归曲线 import numpy as np import pandas as pd from scipy import stat ...
- Spring Colud 学习
转自: http://blog.csdn.net/forezp/article/details/70148833#t0
- 模板引擎-freemarker
Freemarker 是一款模板引擎,是一种基于模版生成静态文件的通用 工具,它是为java程序员提供的一个开发包. 可通过将Word或者Excel模板另存为xml格式,在其中修改要替换的内容. 基本 ...
- WDA-WebDynpro Demo & FPM Demo
Web Dynpro Demo package: SWDP_DEMO SWDP_TEST FPM Demo package: APB_FPM_DEMO APB_FPM_DEMO_SCENARIO
- Qt 信号槽
Qt4与Qt5的信号槽有些不同: 1. Qt4的槽函数必须使用slots关键字声明,而Qt5中已经不再需要了,槽函数可以是任何能和信号关联的成员函数. 2. Qt4指定信号函数和槽函数需用SIGNAL ...