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. PHP中间件--ICE

    ICE(Internet Communications Engine)是Zeroc提供的一款高性能的中间件.使用ICE能使得php(或c++,java,python)与java,c++,.net,py ...

  2. node 删除文件 和文件夹

    删除文件 var fs = require('fs'); fs.unlink(path,callback); 删除文件夹 deleteFolder(path); function deleteFold ...

  3. shiro 没有权限异常处理

    <bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver"> ...

  4. go遍历目录

    package main import ( "fmt" "io/ioutil" "os" "path/filepath" ...

  5. AS3 注意点

    当主类new 一个主影片来放内容的时候.在gc此swf时,一定要检查此主影片是否存在,如 private function initStart() { //trace("RightMenu类 ...

  6. WP8.1 控件默认字体颜色 配置文件位置

    C:\Program Files (x86)\Windows Phone Kits\8.1\Include\abi\Xaml\Design\generic.xaml 可在App.xaml文件中over ...

  7. Nginx 反向代理、后端检测模块

    简介: Nginx 反向代理模块:ngx_http_proxy_module.ngx_http_upstream_module 后端检测模块:nginx_http_upstream_check_mod ...

  8. mysql 导出sql结果成csv文件

    mysql -uroot -p -e "use database;sql语句:" > a.csv 举例: mysql -uroot -p -e "use main; ...

  9. codeblocks 更换颜色主题

    关闭codeblocks,下载主题文件(colour_themes.conf).在关闭codeblocks的情况下,linux下的~/.config/codeblocks/下有个conf文件,将其备份 ...

  10. C & C++ 宏与const

    1.宏定义函数: 例:#define do{exp} while(0)与#define exp有什么不同,好处在哪里? 定义复杂代码,防止分号,或是括号不匹配等错误.比如: 定义: #define s ...