⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 6.42.c

📁 数据结构习题及答案
💻 C
字号:
6.42③ 编写递归算法,计算二叉树中叶子结点的数目。

要求实现下列函数:
void Leaves(BiTree bt, int &x);
/* Count the leaf node of the BiTree */
/* whose root node is bt to x.       */

二叉链表类型定义:
typedef struct BiTNode {
    TElemType data;
    BiTNode  *lchild, *rchild;
} BiTNode, *BiTree;
void Leaves(BiTree bt, int &x)
/* Count the leaf node of the BiTree */
/* whose root node is bt to x.       */
{   int x0,x1;
    if(!bt) x=0;
    else if(!bt->rchild&&!bt->lchild) x=1;
    else {
          Leaves(bt->rchild,x0);
          Leaves(bt->lchild,x1);
          x=x0+x1;
           }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -