建立二叉树,并实现先序遍历( 用递归)

来源:百度知道 编辑:UC知道 时间:2024/05/16 17:08:42
任务:要求能够输入树的各个结点,并能够输出先序遍历序列;
要求:分别建立二叉树存储结构的输入函数、输出层序遍历序列的函数、输出先序遍历序列的函数;
您可以把答案发送到我的邮箱里面把名字打上去``
我到时候再给你加分~
我的邮箱:xiexiufeng0414@yahoo.com.cn
用c语言编,其他不行啊,这是老师要求的。
哦还有怎么输入树,举例

我这里有,发给你吧!!

你看这2个哪个符合你的要求
我想了半天了,我不太会弄这个
#include <stdio.h> /*如发现bug请给我留言*/
#include <conio.h>
#include <stdlib.h>
#define LEN sizeof(struct node)
struct node
{
char data;
struct node *lchild,*rchild;
};
struct node *build()
{
struct node *stack[20]={NULL},*root,*temp,*p;
char c;
int i=-1;
c=getch();
if(c=='0')
return NULL;
root=p=(struct node *)malloc(LEN);
p->data=c;
c=getch();
while(1)
{
while(c!='0')
{
stack[++i]=p;
p=(struct node *)malloc(LEN);
p->data=c;
stack[i]->lchild=p;
c=getch();
}
p->lchild=NULL;
c=getch();
while(c=='0'&&i>=0)
{
p->rchild=NULL;
p=stack[i--];
c=getch();
}
if(c!='0')
{
temp=(struct node *)malloc(LEN);
p->rchild=temp;
temp-&