父节点就是后继结点
代码:
struct TreeNode { int data; TreeNode* leftChild; TreeNode* rightChild; TreeNode* parent; }; TreeNode* findContinue(const TreeNode* vNode) { if (vNode == NULL) return NULL; if (vNode->rightChild != NULL) { TreeNode* Tmp = vNode->rightChild; while (Tmp->leftChild != NULL) { Tmp = Tmp->leftChild; } return Tmp; } TreeNode* Cur = vNode; TreeNode* pParent = Cur->parent; while (pParent != NULL && pParent->rightChild == Cur) { Cur = pParent; pParent = pParent->rightChild; } return pParent; }
018给定二叉查找树的一个结点, 写一个算法查找它的“下一个”结点“(keep it up)
原文地址:http://blog.csdn.net/xiaoliangsky/article/details/39016805