#include
using namespace std;
typedef char DataType;
//二叉树数据结构
struct node
{
DataType info ; //存放结点数据
struct node *lchild , *rchild ; //指向左右孩子的指针
};
typedef struct node *BiTree ;
/*创建二叉树
函数名:createBiTree
参数:无
返回值:二叉树根结点指针
*/
BiTree createBiTree(void)
{
char ch ;
BiTree root ;
cin>>ch ;
if(ch == ‘#’) root = NULL;
else{
root = new struct node ;
root->info = ch ;
root->lchild = createBiTree() ;
root->rchild = createBiTree();
}
return root ;
}
void visit(BiTree T)
{
cout<info ;
}
int countLeaf(BiTree root)
{
//请在此处填写代码, 计算二叉树中树叶的个数
/********** Begin **********/
if(!root)
return 0; //空树,无叶子
else if(!root->lchild && !root->rchild)
return 1;
else
return (countLeaf(root->lchild) + countLeaf(root->rchild));
/********** End **********/
}
int main(void)
{
BiTree root = createBiTree();
cout<<countLeaf(root);
}