https://github.com/Premiumlab/Python-for-Algorithms--Data-Structures--and-Interviews/blob/master/Trees/Tree%20Representation%20Implementation%20(Lists).ipynb

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的更多相关文章

  1. [LeetCode] Binary Tree Vertical Order Traversal 二叉树的竖直遍历

    Given a binary tree, return the vertical order traversal of its nodes' values. (ie, from top to bott ...

  2. [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 ...

  3. [LeetCode] Binary Tree Level Order Traversal 二叉树层序遍历

    Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, ...

  4. LeetCode Binary Tree Vertical Order Traversal

    原题链接在这里:https://leetcode.com/problems/binary-tree-vertical-order-traversal/ 题目: Given a binary tree, ...

  5. 【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, ...

  6. LeetCode之Binary Tree Level Order Traversal 层序遍历二叉树

    Binary Tree Level Order Traversal 题目描述: Given a binary tree, return the level order traversal of its ...

  7. 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 ...

  8. LeetCode:Binary Tree Level Order Traversal I II

    LeetCode:Binary Tree Level Order Traversal Given a binary tree, return the level order traversal of ...

  9. 【Binary Tree Level Order Traversal II 】cpp

    题目: Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from ...

随机推荐

  1. url参数带点

    今天在处理一些接口的时候,发现了一些神奇bug. url路径参数/binbin没有问题 但是/jay.chou 发现查不到正确数据了. 其实是spring没有配置好参数带点的情况. RequestMa ...

  2. 从Chrome 69.0 版本起,Flash权限受到进一步限制,默认仅在当前浏览器会话有效。

    # 69.0 之后的版本 ## 从Chrome 69.0 版本起,Flash权限受到进一步限制,默认仅在当前浏览器会话有效.关闭Enable Ephemeral Flash Permissions , ...

  3. Mybatis like模糊查询的写法

    转自:http://blog.51cto.com/lavasoft/1386870 Mybatis like查询官方文档没有明确的例子可循,网上搜索了很多,都不正确. Mybatis 3.2.6经过尝 ...

  4. eclipse包层级显示和工作空间显示

    本文两件事:设置包层级显示.设置工程的工作空间显示 一.各package包分层显示 平铺显示,实在不方便开发!也不方便查看工程包的层级结构,如下: 更换成层级显示: 二.工作空间显示 包用来区分类,工 ...

  5. C#--抽象工厂设计模式原理

    C#--抽象工厂设计模式原理 C#--抽象工厂设计模式--三层框架 C#--使用反射改进简单工厂

  6. 快速可靠网络传输协议 KCP(转)

    KCP 是一个快速可靠协议,能以比 TCP浪费10%-20%的带宽的代价,换取平均延迟降低30%-40%,且最大延迟降低三倍的传输效果.纯算法实现,并不负责底层协议(如UDP)的收发,需要使用者自己定 ...

  7. 树莓派3用create_ap变身无线AP

    1.git clone https://github.com/oblique/create_ap.git2.cd create_ap3.sudo make install就这样安装好了4.接下来安装依 ...

  8. HTML CSS + DIV实现整体布局 part1

    HTML CSS + DIV实现整体布局 1.技术目标: 开发符合W3C标准的Web页面 理解盒子模型 实现DIV+CSS整体布局 2.什么是W3C标准? W3C:World Wide Web Con ...

  9. hibernate 中一对多的注解配置

    //一方@Entity@Table(name="test_classinfo")public class ClassInfo { @Id @SequenceGenerator(na ...

  10. Flexvolume

    https://kubernetes.io/docs/concepts/storage/volumes/ https://github.com/kubernetes/community/blob/ma ...