基于travseral结果恢复二叉树的逻辑,java

基于travseral结果恢复二叉树的逻辑,java,java,tree,binary-tree,tree-traversal,Java,Tree,Binary Tree,Tree Traversal,你能解释一下如何根据遍历结果绘制原始二叉树的逻辑吗?我知道预顺序和顺序遍历,但我不知道从哪里开始这个问题。非常感谢 A binary tree has this pre-order traversal result: A,B,D,H,I,E,F,C,G,K,J (TreeNodes) And the same tree gives the following in-order traversal: B,H,I,D,A,C,F,E,K,G,J. Can you draw the tree st

你能解释一下如何根据遍历结果绘制原始二叉树的逻辑吗?我知道预顺序和顺序遍历,但我不知道从哪里开始这个问题。非常感谢

A binary tree has this pre-order traversal result: A,B,D,H,I,E,F,C,G,K,J (TreeNodes) 
And the same tree gives the following in-order traversal: B,H,I,D,A,C,F,E,K,G,J. 
Can you draw the tree structure? 

你必须把这两种信息结合起来。 首先:

预订单以root=>A开始。 从中,您可以从以下位置查看属于左子树和右子树的节点:

左-B,H,I,D

右-C,F,E,K,G,J

从预排序中可以看到:A的左子级是B。 从顺序中,您可以看到哪些节点属于B的左子树和右子树:

左-无

对-H,I,D

继续