?? homework4.cpp
字號:
#include<stdio.h>
#include<stdlib.h>
typedef char DataType;
typedef struct node
{
DataType data;
struct node *lchild,*rchild;
}BinTNode;
typedef BinTNode *BinTree;
int count;
void CreateBinTree(BinTree *T);
void Leafnum(BinTree T);
main()
{BinTree T;
char ch1,ch2;
printf("welcome to you:\n");
ch1='y';
while(ch1=='y'||ch1=='Y')
{printf("\nA---------------二叉樹建立");
printf("\nB---------------count the leaf");
printf("\nC---------------quit\n");
scanf("\n%c",&ch2);
switch(ch2)
{case 'a':
case 'A':printf("請輸入按先序建立二叉樹的結(jié)點序列:\n");
CreateBinTree(&T);break;
case'b':
case'B':count=0;Leafnum(T);
printf("該二叉樹有%個葉子。\n",count);
case'c':
case'C':ch1='n';break;
default:ch1='n';
}
}return 0;
}
void CreateBinTree(BinTree *T)
{
char ch;
scanf("\n%c",&ch);
if(ch=='0') *T=NULL;
else{*T=(BinTNode*)malloc(sizeof(BinTNode));
(*T)->data=ch;
CreateBinTree(&(*T)->lchild);
CreateBinTree(&(*T)->rchild);
}
}
void Leafnum(BinTree T)
{
if(T)
{if(T->lchild==NULL&&T->rchild==NULL)
count++;
Leafnum(T->lchild);
Leafnum(T->rchild);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -