首页 > 试题广场 >

设二叉链树的类型定义如下:

[问答题]

设二叉链树的类型定义如下:

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);

}

}

发表于 2017-05-14 22:19:13 回复(0)