孩子兄弟表示法存储结构
typedef struct CSNode{
ElemType data;
struct CSNode *firstchild,*nextsibling;
}CSNode,*CSTree;
当森林以孩子兄弟表示法存储时。若结点无孩子,则为叶结点;总叶子结点个数是孩子上的叶子数和兄弟子树上叶子结点数之和。
typedef struct node{
ElemType data;
struct node *fch,*nsib;
}*Tree;
int leaves(Tree t){
if(t==NULL){
return 0;
}
if(t->fch==NULL){
return 1+leaves(t->nsib);
}
else
return leaves(r->fch)+leaves(t->nsib);
}