0
我试图实现一个函数,该函数查找二叉树中给定节点的父节点,但函数始终返回根节点。我不知道如何使它工作。我一直在努力几天。试图找到二进制树中的节点的父节点
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;
}