钠与四氯化钛反应现象:二叉树遍历
来源:百度文库 编辑:中财网 时间:2024/05/10 06:16:43
#include
#include
#include
typedef struct BiTNode
{
char data;
struct BiTNode *lchild,*rchild;
}BiTNode,*BiTree;
BiTree Create(BiTree T)
{
char ch;
ch=getchar();
if(ch=='#')
T=NULL;
else
{
T=(BiTNode *)malloc(sizeof(BiTNode));
if(!T)printf("Error!");
T->data=ch;
T->lchild=Create(T->lchild);
T->rchild=Create(T->rchild);
}
return T;
}
void Preorder(BiTree T)
{
if(T)
{
printf("%c",T->data);
Preorder(T->lchild);
Preorder(T->rchild);
}
}void Inorder(BiTree T)
{
if(T)
{
Inorder(T->lchild);
printf("%c",T->data);
Inorder(T->rchild);
}
}void Postorder(BiTree T)
{
if(T)
{
Postorder(T->lchild);
Postorder(T->rchild);
printf("%c",T->data);
}
}
int leaves(BiTree T)
{
int sum=0,m,n;
if(T)
{
if((!T->lchild)&&(!T->rchild))sum++;
m=leaf(T->lchild);
sum+=m;
n=leaf(T->rchild);
sum+=n;
}
return sum;
}
void main()
{
int sum;
BiTree T;
printf("请以先序遍历的方式输入二叉树(结点没有左右孩子时用以#表示)\n");
T=Create(T);
printf("先序遍历:");
Preorder(T);
printf("\n");
printf("中序遍历:");
Inorder(T);
printf("\n");
printf("后序遍历:");
Postorder(T);
printf("\n");
printf("叶子结点个数为:\n");
sum=leaves(T);
printf("%d",sum);
}
#include
#include
typedef struct BiTNode
{
char data;
struct BiTNode *lchild,*rchild;
}BiTNode,*BiTree;
BiTree Create(BiTree T)
{
char ch;
ch=getchar();
if(ch=='#')
T=NULL;
else
{
T=(BiTNode *)malloc(sizeof(BiTNode));
if(!T)printf("Error!");
T->data=ch;
T->lchild=Create(T->lchild);
T->rchild=Create(T->rchild);
}
return T;
}
void Preorder(BiTree T)
{
if(T)
{
printf("%c",T->data);
Preorder(T->lchild);
Preorder(T->rchild);
}
}void Inorder(BiTree T)
{
if(T)
{
Inorder(T->lchild);
printf("%c",T->data);
Inorder(T->rchild);
}
}void Postorder(BiTree T)
{
if(T)
{
Postorder(T->lchild);
Postorder(T->rchild);
printf("%c",T->data);
}
}
int leaves(BiTree T)
{
int sum=0,m,n;
if(T)
{
if((!T->lchild)&&(!T->rchild))sum++;
m=leaf(T->lchild);
sum+=m;
n=leaf(T->rchild);
sum+=n;
}
return sum;
}
void main()
{
int sum;
BiTree T;
printf("请以先序遍历的方式输入二叉树(结点没有左右孩子时用以#表示)\n");
T=Create(T);
printf("先序遍历:");
Preorder(T);
printf("\n");
printf("中序遍历:");
Inorder(T);
printf("\n");
printf("后序遍历:");
Postorder(T);
printf("\n");
printf("叶子结点个数为:\n");
sum=leaves(T);
printf("%d",sum);
}
二叉树遍历程序
二叉树的遍历
二叉树遍历问题
二叉树的遍历
关于二叉树的遍历
有关二叉树的遍历
二叉树遍历的程序怎么写?
谁会写二叉树的遍历操作????
二叉树的层次遍历算法
关于二叉树遍历的问题
什么是二叉树数的遍历
什么是二叉树数的遍历
二叉树中的层序遍历?
二叉树的层次遍历问题(java)
二叉树的遍历问题,高手请进
二叉树的遍历问题,高手请进
在vb中实现二叉树的建立及遍历
vc++ 做的二叉树建立和遍历
那么二叉树中的各种遍历序列又是怎么回事呢?
求二叉树遍历算法C语言实现的
急急急!!!!二叉树遍历的算法怎么算呀
求java实现二叉树启遍历的算法
pascal 二叉树的顺序结构的中序遍历
怎样 用数据结构编写 遍历二叉树的程序啊