您的位置:首页 > 其它

找出二叉树中序遍历的所求节点的下一个节点

2012-09-07 21:32 211 查看
typedef struct node
{
int data;
struct node* left;
struct node* right;
struct node* parent;
}NODE;

NODE *findSuccessorInorder(NODE* node)
{
NODE *pNode = node;

if (pNode->right != NULL)
{
pNode = pNode->right;
while (pNode->left != NULL)
{
pNode = pNode->left;
}

return pNode;
}
else if (pNode->parent)
{
NODE *pParent = pNode->parent;

while (pParent && pParent->right == pNode)
{
pNode = pParent;
pParent = pNode->parent;
}

return pParent;
}
else
{
return NULL;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: