#include <iostream>
#include <stdlib.h>
using namespace std;
int leaf=0,node=0;
typedef struct bitnode
{
char data;
struct bitnode* lchild;
struct bitnode* rchild;
}bitnode,*bitree;
void create(bitree &bt)
{
char data;
cin>>data;
if(data=='#')
bt=NULL;
else
{
bt=(bitree)malloc(sizeof(bitnode));
bt->data=data;
create(bt->lchild);
create(bt->rchild);
}
}
void successive(bitree bt)
{
if(bt!=NULL)
{
if(bt->lchild==NULL && bt->rchild==NULL)
{
leaf++;
node++;
}
else
{
node++;
}
successive(bt->lchild);
successive(bt->rchild);
}
}
int main()
{
bitree bt;
create(bt);
successive(bt);
cout<<leaf<<endl<<node;
}
162-15
最新推荐文章于 2024-09-10 20:37:53 发布