求两个节点的父节点大体分两种方法:
typedef struct BiNode { struct BiNode *lchild,*rchild; int data; }BiNode,*BiTree;
第一种是直接递归寻找:
BiNode* findConmmonFather(BiTree root,char a,char b){
if(NULL==root)
return NULL;
if(root->data==a||root->data==b)
return root;
BiNode* l = findConmmonFather(root->lchild,a,b);
BiNode* r = findConmmonFather(root->rchild,a,b);
if(NULL==l)
return r;
if(NULL==r)
return l;
return root;
}
第二种方法是通过两个辅助栈实现,把遍历的节点存储到栈中
代码略.....