【发布时间】:2016-05-19 16:27:53
【问题描述】:
我想将第二棵树插入到与其根同名的节点中的第一棵树中,并将该节点的子节点附加到第二棵树的最左侧子节点。
我试过了:
PTree attachPoint = chain.Find(x => x.Val == RTree.Val);
if (attachPoint != null)
{
foreach (var c in attachPoint.Childs)
{
RTree.Left.Childs.Add(c);
}
attachPoint = RTree;
}
else
{
RTree.Left.Childs.Add(root);
root = RTree;
}
这里,RTree 是第二棵树,root 指向第一棵树的根,chain 持有从根“A”到“D”的分支。但似乎没有建立所需的树。我做对了吗?
【问题讨论】:
-
一个节点的最大子节点数是多少?这看起来不像二叉树,但一个节点包含一个
Left-child-node。看起来很奇怪。 -
@Verarind 你可以假设
RTree,第二个孩子,是二元的,Left实际上是 childs[1] 而Right是childs[0]