请帮忙解决有关数据结构的一个问题

来源:百度知道 编辑:UC知道 时间:2024/09/23 01:40:33
请帮我给这个程序做一个程序分析,最好能详细点麻烦了
#include "stdio.h"
#include "conio.h"
#define M 20
typedef struct node
{char data;struct node *lch,*rch;}BTnode;
BTnode *create()
{BTnode *t;
char ch;
scanf("%c",&ch);
if(ch=='#')
t=NULL;
else
{t=(BTnode *)malloc(sizeof(BTnode));
t->data=ch;
t->lch=create();
t->rch=create();
}
return t;
}

/*zhongxu*/
void Ino(BTnode *t)
{int i=0;
BTnode* s[M];
do{while(t!=NULL)
{s[i++]=t;t=t->lch;}
if(i>0)
{t=s[--i];
printf("%c",t->data);
t=t->rch;
}
}while(i>0||t!=NULL);
}

/*qianxu*/
void Pre(BTnode *t)
{int i=0;
BTnode *s[M];
do{while(t!=NULL)
{printf("%c",t->data);
if(t->rch!=NULL)
s[i++]=t->rc

这是一个数据结构中,树的遍历算法

定义:char data;struct node *lch,*rch分别是只树的一个节点的值,以及它的左孩子(lch)右孩子(rch)

然后线面分别写了三种树遍历的方式,分别是:中序,前序,后序
其中中序:左孩子 结点 右孩子
前序:结点 左孩子 右孩子
后序:左孩子 右孩子 结点
三种顺序分别按这样的顺序遍历每一个结点