设二叉链树的类型定义如下:
typedef int Elemtype;
typedef struct node{
Elemtype data;
struct node *lchild, *rchild;
}BinNode, *BinTree;
试写出求该二叉树叶子结点数的算法:
S tatus CountLeaves(BinTree &root,int &n)
{//n is the number of leaves
……
}
voidCountLeaves(BinTree T,int &n)
{
if(T)
if((!(T->lchild)&&!( T->rchild)) n++;
CountLeaves (T->lchild,n);
CountLeaves (T->rchild,n);
这道题你会答吗?花几分钟告诉大家答案吧!
扫描二维码,关注牛客网
下载牛客APP,随时随地刷题