完整代碼如下:
#include <stdio.h>
#include <malloc.h>
#include <conio.h>
typedef char DataType;
typedef struct Node
{
DataType data;
struct Node *LChild;
struct Node *RChild;
}BiTNode, *BiTree;
void CreateBiTree(BiTree *bt)
{
char ch;
ch = getchar();
if(ch=='#') *bt=NULL;
else
{
*bt=(BiTree)malloc(sizeof(BiTNode)); //生成一個新結點
(*bt)->data=https://bbs.csdn.net/topics/ch;
CreateBiTree(&((*bt)->LChild)); //生成左子樹
CreateBiTree(&((*bt)->RChild)); //生成右子樹
}
}
int count(BiTNode* p)
{
int a,b,c;
if(p==NULL)
return 0;
else
{
a=count(p->LChild);
b=count(p->RChild);
}
return a+b+1;
}
void countleaf(BiTNode *p)
{
int count=0;
if(p!=NULL)
{
countleaf(p->LChild);
countleaf(p->RChild);
if(p->LChild==NULL&&p->RChild==NULL)
{
count=count+1;
}
}
return count;
}
int main()
{
BiTree T;
printf("\n結點總數:\n");
count(T);
printf("\n葉子結點總數:\n");
countleaf(T);
printf("\n%d");
}
uj5u.com熱心網友回復:
回傳值是int型的,你寫的是void型的轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/44879.html
標籤:數據結構與算法
上一篇:python爬蟲
下一篇:求薦一個嗶哩嗶哩視頻下載的網站
