1 / 33
文档名称:

软件基础实验报告.doc

格式:doc   大小:1,622KB   页数:33页
下载后只包含 1 个 DOC 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

软件基础实验报告.doc

上传人:Alone-丁丁 2022/7/19 文件大小:1.58 MB

下载得到文件列表

软件基础实验报告.doc

文档介绍

文档介绍:软件基础实验报告
2
计算机软件技术基础
实验报告
姓名:XXX
班级:XX 0X01
学号:30X05050XX
3
linklik;
case 6:exit(0);break;
}
}
while(1);
}
运行结果:
实验总结:,对于循环的计数的控制没有搞好,以致无法得到想要的链表;,否则会出错。
10
解决办法:,调整循环次数,来使循环中的个参数达到自己想要的通过查阅资料,完成对链表程序的实现。在写每一个子函数时,常常会遗漏小的判断条件,比如遗漏了判断是否为空等;还有就是在对指针操作时,有时多加了*,或者分号写成逗号;在调试程序的过程中有很多小的错误或者判断条件错误等。
实验二
在交互方式完成下列任务:
1、动态交互建立二叉树,结点个数任意;
2、分别用DLR、LDR、LRD三种方式对二叉树进行便利并输出结果;
3、计算二叉树中的结点个数并输出;
4、计算二叉树的深度并输出;
源程序如下:
# include ""
# include ""
10
struct BTNode
{
int data;
struct BTNode *Lchild,*Rchild;
};
struct BTNode *build(struct BTNode *p);
struct BTNode *creatrent(struct BTNode *p);
void DLR(struct BTNode *T);
struct BTNode *creatrent(struct BTNode *p)
{
int x;
printf("输入根:rent=");
scanf("%d",&x);
if(x==1000) {p=NULL;}
else
{
p->data=x;
p->Lchild=(struct BTNode *)malloc(sizeof(struct BTNode));
p->Rchild=(struct BTNode *)malloc(sizeof(struct BTNode));
if(p==NULL) return p;
11
p->Lchild=build(p->Lchild);
p->Rchild=build(p->Rchild);
return p;
}
}
struct BTNode *build(struct BTNode *p)
{
int x;
printf("输入数据(输入值为时,表示该结点为空):value=");
scanf("%d",&x);
if(x==1000) {p=NULL;}
else
{
p->data=x;
p->Lchild=(struct BTNode *)malloc(sizeof(struct BTNode));
p->Rchild=(struct BTNode *)malloc(sizeof(struct BTNode));
}
if(p==NULL) return p;
12
p->Lchild=build(p->Lchild);
p->Rchild=build(p->Rchild);
return p;

}
void DLR(struct BTNode *T)
{
if(T==NULL) return;
printf("%d ",T->data);
DLR(T->Lchild);
DLR(T->Rchild);
}
void LDR(struct BTNode *T)
{
if(T==NULL) return;

LDR(T->Lchild);
printf("%d ",T->data);
LDR(T->Rchild);
}
void LRD(struct BTNode *T)
13
{