三种遍历的代码:
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/binary-tree-preorder-traversal/ 3 @date 2015.5.13 4 @description 5 用非递归方法对二叉树进行先序...
分类:
其他好文 时间:
2015-05-16 18:19:07
阅读次数:
97
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
题目: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 thepreordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,2,3]....
分类:
其他好文 时间:
2015-05-13 21:31:37
阅读次数:
109
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 preorder traversal of its nodes' values.
For example:
Given binary tree {1,#,2,3},
1
2
/
3
return [1,2,3].
Note: Recursive soluti...
分类:
其他好文 时间:
2015-05-10 09:56:42
阅读次数:
123
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
题目:Given a binary tree, return thepreordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,2,3]....
分类:
其他好文 时间:
2015-05-07 06:27:10
阅读次数:
118
1. 先序遍历public void preorder(TreeNode root) { if(root == null) return; Stack stack = new Stack(); while(true) { if(root...
分类:
其他好文 时间:
2015-05-05 18:51:09
阅读次数:
108