以二叉链表作为存储结构,试编写递归算法实现求二叉树中叶子结点个数。
以二叉链表作为存储结构,试编写递归算法实现求二叉树中叶子结点个数。
【正确答案】:typedef struct btnode {DataType data; struct btnode*lchild,*rchild; }*Bintree; int Leafnode—num(Bintree bt) {if(bt==NULL)retum 0; else if(bt一>lchild==NULL)&&(bt一>rchild==NULL) return 1; else return(Leafnode—Bum(bt一>lehild)+Leafnode—Bum(bt一>rchild)); }
Top