二叉树中查找值为x的结点,打印x结点的全部祖先

来源:互联网 发布:小众app 知乎 编辑:程序博客网 时间:2024/04/20 14:15

二叉树中查找值为x的结点,打印x结点的全部祖先

int PrintAncestors(PBinTree root, int x){    if (!root)  return 0;    if (root->data == x)    return 1;    //如果子树中可以找到匹配值 那么此节点肯定是祖先结点    if (PrintAncestors(root->lchild, x) || PrintAncestors(root->rchild, x))    {        printf("%c ", root->data);        return 1;    }    return 0;}//打印祖先
阅读全文
0 0