C语言 ~~~~~树的遍历

来源:百度知道 编辑:UC知道 时间:2024/09/19 15:52:48
struct tree
{
char data;
struct tree *Lsubtree,*Rsubtree;
};
struct stack
{
struct tree *a[100];
int top,bottom;
}s;
#include<malloc.h>
#include<stdio.h>
#define NULL 0
void main()
{
s.top=-1;
s.bottom=100-1;
struct tree *p;
p=NULL;
printf("请输入您要存储的数字(按“.”为叶子)。\n");
void creattree(struct tree *T);
creattree(p);
printf("输入结束!\n");
void Inorder(struct tree *T);
Inorder(s.a[0]);
}
void creattree(struct tree *T)
{
void pushstack(struct tree *T);
char i;
scanf("%s",&i);
if(i=='.')
{
T=NULL;
printf("此为叶子!\n");
}
else
{
T=(struct tree *)malloc(sizeof(struct tree));
T->data=i;
pushstack(T);
creattree(T->Lsubtree);
creattree(T->Rsubtree);
}
}
voi

#include<malloc.h>
#include<stdio.h>
#define NULL 0
struct tree
{
char data;
struct tree *Lsubtree,*Rsubtree;
};
struct stack
{
struct tree *a[100];
int top,bottom;
}/*s*/;
stack s;//
void creattree(struct tree **T);//
void Inorder(struct tree *T); //
void main()
{
s.top=-1;
s.bottom=100-1;
struct tree *p;
p=NULL;
printf("请输入您要存储的数字(按“.”为叶子)。\n"); //不是叶子是空结点
//void creattree(struct tree *T);
creattree(&p); //
printf("输入结束!\n");
//void Inorder(struct tree *T);
Inorder(s.a[0]);
}
void pushstack(struct tree *T);//
void creattree(struct tree **T) //
{
//void pushstack(struct tree *T);
char i;
scanf("%s",&i);
if(i=='.')
{
*T=NULL;
printf("此为叶子!\n"); //空结点
}
else
{
(*T)=(struct