数据结构

请教下,以下程序哪里出现错误,如何改正,谢谢。

//  编写递归算法,计算二叉树中叶子结点的数目。

#include <stdio.h>

 #include<malloc.h> 

 struct node

 {  

char info; 

struct node *llink, *rlink; 

 };  

 typedef struct node NODE;   NODE *create()

 {               //构造二叉树   

char x;  

NODE *p;  

scanf("%c", &x);   

printf("%c", x);              //打印出已输入的二叉树 

if(x!='.')

{   p=(NODE *)malloc(sizeof(NODE)); 

p->info=x;  

p->llink=create();  

p->rlink=create();  }   

else  

p=NULL; 

return p; 

 }  

 int run(NODE *t)

 {  static int count=0; 

 if(t)

 {run(t->llink);

 run(t->rlink);

 if(t->llink ==NULL && t->rlink == NULL)

 {  count++; 

 }

 return count++;

 }

void  main() 

 { NODE *t; 

 int left_number;  

 printf("请输入一棵树:\n" ); 

 t=create(); 

 printf("\n");  

 if(!t)   

printf("This is a empty binary tree.");  

 else

 {   

left_number=run(t);  

printf("\n这棵树共有 %d 个子叶. \n", left_number); 

 }  

 printf("\n");

 } 

 }


buccy
浏览 2362回答 0
0回答
打开App,查看更多内容
随时随地看视频慕课网APP