【发布时间】:2016-11-06 06:22:17
【问题描述】:
我正在尝试实现一个在二叉树中查找给定节点的父节点的函数,但该函数始终返回根节点。我不知道如何使它工作。我已经尝试了好几天了。
Tree* NodeParent(Tree* a, char c)
{
Tree *parent = a;
if (!EmptyTree(a))
{
if ((!EmptyTree(a->Left) && info(a->Left) == c)
|| (!EmptyTree(a->Right) && info(a->Right) == c))
return parent = a;
else
{
NodeParent(a->Left, c);
NodeParent(a->Right, c);
}
}
return parent;
}
还有树形结构
struct tree
{
char c;
Tree* Left;
Tree* Right;
}
【问题讨论】:
标签: c binary-tree