安徽省巢湖学院计算机与信息工程学院
课程设计报告
课程名称 《数据结构》
课题名称 二叉树的二叉链表表示
专 业 计算机科学与技术
班 级 10计本2班
学 号
姓 名 张亚飞
联系方式
指导教师 江家宝
20 年 月 日
目 录
1、数据结构课程设计任务书 1
1.1、题目 1
1.2、要求 1
2、总体设计 1
2.1、功能模块设计 1
2.2、所有功能模块的流程图 1
3、详细设计 1
3.1、程序中所采用的数据结构及存储结构的说明 1
3.2、算法的设计思想 2
3.3、稀疏矩阵各种运算的性质变换 2
4、调试与测试: 2
4.1、调试方法与步骤: 2
4.2、测试结果的分析与讨论: 3
4.3、测试过程中遇到的主要问题及采取的解决措施: 3
5、时间复杂度的分析: 4
6、源程序清单和执行结果 4
7、C程序设计总结 8
8、致谢 8
9、参考文献 8
1、数据结构课程设计任务书
1.1、题目
1.2、要求
2、总体设计
2.1、功能模块设计
根据课程设计题目的功能要求,各个功能模块的组成框图如下:#define maxsize 100
typedef struct
{
Bitree Elem[maxsize];
int top;
}SqStack;
void PreOrderUnrec(Bitree t)
{
SqStack s;
StackInit(s);
p=t;
while (p!=null || !StackEmpty(s))
《数据结构》习题解
{
while (p!=null) //遍历左子树
{
visite(p-data);
push(s,p);
p=p-lchild;
}//endwhile
if (!StackEmpty(s)) //通过下一次循环中的内嵌 while 实现右子树遍历
{
p=pop(s);
p=p-rchild;
}//endif
}//endwhile
}//PreOrderUnrec
6-12 写一算法求二叉树中结点的总数,可以写出多少种方法?
答案:
#include stdio.h
#include stdlib.h
typedef struct node
{ char data; /*此例中二叉树的结点采用字符类型*/
struct node *lchild, *rchild;
}NODE;
NODE *crt_bt_pre( ) /*按先序遍历序列创建二叉树的二叉链表*/
{
/* 输入 ABC00DE0G00F000 */
NODE *bt;
char ch;
printf(\n\t\t\t);
scanf(%c,ch);
getchar( );
if(ch== )
bt=NULL;
else
{
bt=(NODE *)malloc(sizeof(NODE));
bt-data=ch;
printf(\n\t\t\t 请输入%c 结点的左孩子:,bt-data);
bt-lchild=crt_bt_pre( );
printf(\n\t\t\t 请输入%c 结点的右孩子:,bt-data);
bt-rchild=crt_bt_pre();
}
return(bt);
}
《数据结构》习题解
void CountNode(NODE* bt,int *p) /*统计二叉树中结点的总数*/
{
if(bt==NULL)
return;
else
{
(*p)++;
CountNode(bt-lchild,p);
CountNode(bt-rchild,p);
return;
}
}
main()
{ NODE *crt_bt_pre( )
CountNode(bt,b); /*调用统计结点总数的函数*/
printf(\n\t\t\t 该二叉树共有%d 个结点。\n,b);
}
6-13 写一算法将二叉树中所有结点的左、右子树相互交换。
答案:
#include datastru.h
#include stdio.h
#include malloc.h
原创力文档

文档评论(0)