
bool ancestor(Bitree bt,Elemtype x) { if(bt==NULL) //遞歸出口 return false; else if(bt->lchild!=NULL&&bt->rchild->data==x||bt->rchild->data==x&&bt->lchild!=NULL) { //結點的左孩子或者右孩子的data為x printf("%c",bt->data); return true; } else if(ancestor(bt->lchild,x)||ancestor(bt->rchild,x)) { printf("%c",bt->data); return true; } else return false; }