📄 erchashuyezijiedianshu.c
字号:
#include<iostream.h>
#include<malloc.h>
#define LEN sizeof(struct BiTree)
struct BiTree{
char data;
struct BiTree *lchild;
struct BiTree *rchild;
};
char ch;
void CreateBiTree(struct BiTree *&T) {//按先序输入二叉树结点的值
cin>>ch;
if (ch=='#') {
T=NULL;
}
else {
T = (struct BiTree* )malloc(sizeof(struct BiTree));
T->data = ch; // 生成根结点
CreateBiTree(T->lchild); // 构造左子树
CreateBiTree(T->rchild); // 构造右子树
}
// return s;
} // CreateBiTree
void visit(char &e){
cout<<e<<endl;
}
int CountLeaf (BiTree*& T) {
if (T==NULL) return 0;
else if (T->lchild==NULL &&
T->rchild==NULL) return 1;
else return CountLeaf(T->lchild) +
CountLeaf(T->rchild);
}
void main(){
BiTree*tree;
CreateBiTree(tree);
cout<<CountLeaf(tree);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -