主题:帮忙分析一下,谢谢了
请将下面的程序帮我分析一下,越详细越好,我是处学者,有的地方看不明白,谢谢,
#include "stdio.h"
#include "stdlib.h"
typedef struct node
{
char data;
struct node *lchild,*rchild;
}bitree;
int count;
bitree *createbintree();
void levelorder(bitree *t);
void leafnum(bitree *t);
void nodenum(bitree *t);
void main()
{
bitree *root;
root=0;
root=createbintree();
levelorder(root);
count=0;
leafnum(root);
printf("该二叉树有%d个叶子!\n",count);
count=0;
nodenum(root);
printf("该二叉树总共有%d个结点!\n",count);
}
bitree *createbintree()
{
char ch;
bitree *root;
scanf("%c",&ch);
if(ch=='*')
root=0;
else
{
root=(bitree*)malloc(sizeof(struct node));
root->data=ch;
root->lchild=createbintree();
root->rchild=createbintree();
}
return(root);
}
void levelorder(bitree *t)
{
int i,j;
bitree *q[20],*p;
p=t;
if(p!=0)
{
i=1;
q[i]=p;
j=2;
}
while(i!=j)
{
p=q[i];
printf("%c",p->data);
if(p->lchild!=0)
{
q[j]=p->lchild;
j++;
}
if(p->rchild!=0)
{
q[j]=p->rchild;
j++;
}
i++;
}
}
void leafnum(bitree *t)
{if(t)
{if(t->lchild==0&&t->rchild==0)
count++;
leafnum(t->lchild);
leafnum(t->rchild);
}
}
void nodenum(bitree *t)
{
if(t)
{
count++;
nodenum(t->lchild);
nodenum(t->rchild);
}
}
#include "stdio.h"
#include "stdlib.h"
typedef struct node
{
char data;
struct node *lchild,*rchild;
}bitree;
int count;
bitree *createbintree();
void levelorder(bitree *t);
void leafnum(bitree *t);
void nodenum(bitree *t);
void main()
{
bitree *root;
root=0;
root=createbintree();
levelorder(root);
count=0;
leafnum(root);
printf("该二叉树有%d个叶子!\n",count);
count=0;
nodenum(root);
printf("该二叉树总共有%d个结点!\n",count);
}
bitree *createbintree()
{
char ch;
bitree *root;
scanf("%c",&ch);
if(ch=='*')
root=0;
else
{
root=(bitree*)malloc(sizeof(struct node));
root->data=ch;
root->lchild=createbintree();
root->rchild=createbintree();
}
return(root);
}
void levelorder(bitree *t)
{
int i,j;
bitree *q[20],*p;
p=t;
if(p!=0)
{
i=1;
q[i]=p;
j=2;
}
while(i!=j)
{
p=q[i];
printf("%c",p->data);
if(p->lchild!=0)
{
q[j]=p->lchild;
j++;
}
if(p->rchild!=0)
{
q[j]=p->rchild;
j++;
}
i++;
}
}
void leafnum(bitree *t)
{if(t)
{if(t->lchild==0&&t->rchild==0)
count++;
leafnum(t->lchild);
leafnum(t->rchild);
}
}
void nodenum(bitree *t)
{
if(t)
{
count++;
nodenum(t->lchild);
nodenum(t->rchild);
}
}