文档介绍:本科实验报告
课程名称: 数据结构
实验项目: 树形结构
实验地点: 迎西校区逸夫楼302
专业班级:软件1109 学号: 2011004872
学生姓名: 栗永春
指导教师: 牛之贤
年月日
树形结构
一、实验目的和要求
目的与要求
二、实验内容和原理
三、主要仪器设备
四、操作方法与实验步骤
列出调试通过的源程序。<br****题1:
/*********************************************************************
*1. 编写递归算法,计算二叉树中叶子结点的数目。*
*********************************************************************/
#include<>
#include<>
int count = 0;
struct node{
char info;
struct node *llink,*rlink;
};
typedef struct node NODE;
NODE *creat(){
char x;
NODE *p;
scanf("%c",&x);
printf("%c",x);
if(x!='.'){
p=(NODE *)malloc(sizeof(NODE));
p->info=x;
p->llink=creat();
p->rlink=creat();
}
else
p=NULL;
return p;
}
void run(NODE *t){
if(t){
run(t->llink);
run(t->rlink);
printf("%c",t->info);
if( ((t->llink) == NULL) && ((t->rlink) == NULL))
count ++;
}
}
void main()
{
NODE *T;
printf("PLease input a tree:\n");
T=creat();
printf("\n");
if(!T)
printf("This is a empty binary tree.");
else
{ printf("The result of post travese is:\n ");
run(T);
}
printf("总共有叶子节点数%d", count );
printf("\n");
}<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中*
* 。试写出程序。*
*****************************