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;
}
View Code

相关文章:

  • 2021-09-03
  • 2022-12-23
  • 2021-12-31
  • 2022-12-23
  • 2022-12-23
  • 2021-09-08
  • 2021-08-11
  • 2021-04-05
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-09
  • 2022-12-23
  • 2022-01-30
  • 2021-11-21
  • 2022-01-17
相关资源
相似解决方案