三种遍历的代码:
function inOrder(node){//中序遍历
if(node!=null){
inOrder(node.left);
document.write(node.show()+" ");
inOrder(node.right);
}
}
function preOrder(node){//先序遍历
if(node!=null){
...
分类:
编程语言 时间:
2015-05-18 09:15:22
阅读次数:
175
1 /************************** 2 https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/ 3 @date 2015.5.16 4 @descrip....
分类:
其他好文 时间:
2015-05-16 18:16:24
阅读次数:
167
题意:题意比较简单就是二叉树的中序遍历
思路:1. 递归是最简单的了
2. 非递归的实现:用一个stack做存储结构
一直查找leftchild 知道没有下一个leftchild,访问该元素
如果该元素有right child 加入stack
从stack中取出一个元素 重复上述行为(这里需要加入set集合记录访问过得left的节点 否则会出现重复访问的问题)
代码:
...
分类:
其他好文 时间:
2015-05-16 16:34:34
阅读次数:
100
题目:Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.代码:/** * De...
分类:
其他好文 时间:
2015-05-16 13:12:01
阅读次数:
116
题目:Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.代码:/** * Def...
分类:
其他好文 时间:
2015-05-16 11:53:57
阅读次数:
141
题目:Given a binary tree, return theinordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,3,2].N...
分类:
其他好文 时间:
2015-05-13 21:39:39
阅读次数:
126
Title:Given preorder and inorder traversal of a tree, construct the binary tree.使用递归构建。/** * Definition for a binary tree node. * struct TreeNode { * ...
分类:
其他好文 时间:
2015-05-13 18:47:08
阅读次数:
114
题目描述
Given a binary tree, return the inorder traversal of its nodes' values.
For example:
Given binary tree {1,#,2,3},
1
2
/
3
return [1,3,2].
Note: Recursi...
分类:
其他好文 时间:
2015-05-10 17:20:16
阅读次数:
118
Given inorder and postorder traversal of a tree, construct the binary tree.
Note:
You may assume that duplicates do not exist in the tree.
基本思路:
人中序和后序遍历结果中,构造出二叉树。
中序遍历为: {左子树} 根 {右子树}
后序遍...
分类:
其他好文 时间:
2015-05-08 16:34:15
阅读次数:
135
Given preorder and inorder traversal of a tree, construct the binary tree.
Note:
You may assume that duplicates do not exist in the tree.
基本思路:
从前序和中序遍历结果,构造出一个二叉树。
前序遍历为: 根 {左子树的所有结点} {右子树所有...
分类:
其他好文 时间:
2015-05-07 18:59:06
阅读次数:
114