1 / 8
文档名称:

数据结构实验报告实验2.doc

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

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

分享

预览

数据结构实验报告实验2.doc

上传人:840122949 2017/12/5 文件大小:108 KB

下载得到文件列表

数据结构实验报告实验2.doc

文档介绍

文档介绍:本科实验报告
课程名称: 数据结构
实验项目: 树形结构
实验地点: 迎西校区逸夫楼302
专业班级:软件1109 学号: 2011004872
学生姓名: 栗永春
指导教师: 牛之贤

年月日
树形结构
一、实验目的和要求
目的与要求
二、实验内容和原理
三、主要仪器设备
四、操作方法与实验步骤
列出调试通过的源程序。<br****题1:
/*********************************************************************
*1. 编写递归算法,计算二叉树中叶子结点的数目。*
*********************************************************************/
#include&lt;&gt;
#include&lt;&gt;
int count = 0;
struct node{
char info;
struct node *llink,*rlink;
};
typedef struct node NODE;
NODE *creat(){
char x;
NODE *p;
scanf(&quot;%c&quot;,&amp;x);
printf(&quot;%c&quot;,x);
if(x!=&#39;.&#39;){
p=(NODE *)malloc(sizeof(NODE));
p-&gt;info=x;
p-&gt;llink=creat();
p-&gt;rlink=creat();
}
else
p=NULL;
return p;
}
void run(NODE *t){
if(t){
run(t-&gt;llink);
run(t-&gt;rlink);
printf(&quot;%c&quot;,t-&gt;info);
if( ((t-&gt;llink) == NULL) &amp;&amp; ((t-&gt;rlink) == NULL))
count ++;
}
}
void main()
{
NODE *T;
printf(&quot;PLease input a tree:\n&quot;);
T=creat();
printf(&quot;\n&quot;);
if(!T)
printf(&quot;This is a empty binary tree.&quot;);
else
{ printf(&quot;The result of post travese is:\n &quot;);
run(T);
}
printf(&quot;总共有叶子节点数%d&quot;, count );
printf(&quot;\n&quot;);
}<br****题2:
/*********************************************************************
* 用单链表ha 存储多项式A(x )=a0+a1x1+a2x2+…+anxn(其中aI为非零系*
* 数),用单链表hb 存储多项式B(x )=b0+b1x1+b2x2+…+bmxm(其中bj为*
* 非零系数),要求计算C(x )= A(x )+B(x ),结果存到单链表hc中*
* 。试写出程序。*
*****************************