关于二叉树
来源:百度知道 编辑:UC知道 时间:2024/09/13 02:57:51
#include<iostream.h>
#include<stdio.h>
#include<stdlib.h>
typedef struct BiTNode
{
char data;
struct BiTNode *lchild,*rchild;
}BiTNode,*BiTree;
int sum=0;
void exit()
{
return;
}
BiTree CreateBitree(BiTree &T)
{
char ch;
scanf("%c",&ch);
if(ch=='#') T=NULL;
else
{
if(!(T=(BiTNode*)malloc(sizeof(BiTNode))))exit();
T->data=ch;
CreateBitree(T->lchild);
CreateBitree(T->rchild);
}
return T;
}
int DLR(BiTree root)
{
if ( root!=NULL )
{
if(!root->lchild&&!root->rchild)
{
sum++;
printf("%d\n",root->data);
}
DLR(root->lchild);
DLR(root->rchild);
}
return sum;
}
void main()
{
BiTree T;
CreateBitree(T);
int n=DLR(T
#include<stdio.h>
#include<stdlib.h>
typedef struct BiTNode
{
char data;
struct BiTNode *lchild,*rchild;
}BiTNode,*BiTree;
int sum=0;
void exit()
{
return;
}
BiTree CreateBitree(BiTree &T)
{
char ch;
scanf("%c",&ch);
if(ch=='#') T=NULL;
else
{
if(!(T=(BiTNode*)malloc(sizeof(BiTNode))))exit();
T->data=ch;
CreateBitree(T->lchild);
CreateBitree(T->rchild);
}
return T;
}
int DLR(BiTree root)
{
if ( root!=NULL )
{
if(!root->lchild&&!root->rchild)
{
sum++;
printf("%d\n",root->data);
}
DLR(root->lchild);
DLR(root->rchild);
}
return sum;
}
void main()
{
BiTree T;
CreateBitree(T);
int n=DLR(T
#include<iostream.h>
#include<stdio.h>
#include<stdlib.h>
typedef struct BiTNode
{
char data;
struct BiTNode *lchild,*rchild;
}BiTNode,*BiTree;
int sum=0;
void exit()
{
return;
}
BiTree CreateBitree(BiTree &T)
{
char ch;
scanf("%c",&ch);
if(ch=='#') T=NULL;
else
{
if(!(T=(BiTNode*)malloc(sizeof(BiTNode))))exit();
T->data=ch;
CreateBitree(T->lchild);
CreateBitree(T->rchild);
}
return T;
}
int DLR(BiTree root)
{
if ( root!=NULL )
{
if(!root->lchild&&!root->rchild)
{
sum++;
printf("%d\n",root->data);
}
DLR(root->lchild);
DLR(root->rchild);
}
return sum;
}
void main()
{
BiTree T;
CreateBitree(T);
int n=DLR(T);
printf("%d