好文档 - 专业文书写作范文服务资料分享网站

数据结构实验报告5(电大)

天下 分享 时间: 加入收藏 我要投稿 点赞

v1.0 可编辑可修改 实验报告五 查找(学科:数据结构 )

姓名 单位 班级 学号 实验日期

成绩评定 教师签名 批改日期

实验名称:实验五 查找

折半查找

【问题描述】

某班学生成绩信息表中,每个学生的记录已按平均成绩由高到低排好序,后来发现某个学生的成绩没有登记到信息表中,使用折半查找法把该同学的记录插入到信息表中,使信息表中的记录仍按平均成绩有序。 【基本信息】

(1) 建立现有学生信息表,平均成绩已有序。 (2) 输入插入学生的记录信息。

(3) 用折半查找找到插入位置,并插入记录。 【测试数据】 自行设计。 【实验提示】

(1) 用结构数组存储成绩信息表。 (2) 对记录中的平均成绩进行折半查找。

【实验报告内容】 设计程序代码如下: #include<> #include<> #define N 5

struct student{

char name[10]; float avg;

1 1

v1.0 可编辑可修改 }

void insort(struct student s[],int n) { int low,hight,mid,k; char y[10]; float x; low=1; hight=n;

strcpy(y,s[0].name ); x=s[0].avg ; while(low<=hight) { mid=(low+hight)/2; if(x>s[mid].avg )

hight=mid-1;

else

low=mid+1;

}

for(k=0;k

printf(\

strcpy(s[low-1].name ,y) ; s[low-1].avg =x;

}

2 2

v1.0 可编辑可修改

void main() {

Struct student a[N]=

{{\ struct student stu[N]; int i;

for(i=0;i

stu[i+1]=a[i];

printf(\初始 %d 位同学的信息表\\n\ printf(\排名 姓名 平均分数\\n\ for(i=1;i<=N;i++)

printf(\

printf(\ printf(\

printf(\请输入学生的姓名: \ scanf(\ printf(\

printf(\请输入平均成绩: \ scanf(\ printf(\

insort(stu,N);

printf(\折半排序后同学的信息表\\n\ printf(\排名 姓名 平均分数\\n\ for(i=0;i<=N;i++)

{

3 3

v1.0 可编辑可修改 printf(\

}

printf(\

}

程序运行结果如下:

二叉排序树的建立

【问题描述】

参阅相关资料,阅读建立二叉排序树的程序。 【基本要求】

(1) 掌握建立二叉排序树的原理和方法。 (2) 能跟踪程序人工建立二叉排序树。

【实验报告内容】 设计程序代码如下: #include<> #include<> #define MAX 5 typedef struct Bnode {

4 4

v1.0 可编辑可修改 int key;

struct Bnode *left;

struct Bnode *right;

}Bnode;

Bnode * btInsert(int x,Bnode *root); void Inorder(Bnode *root); void main() { int i;

int a[MAX]={60,40,70,20,80}; Bnode * root=NULL;

printf(\按关键字序列建立二叉排序树\\n\ for(i=0;i

for(i=0;i

}

Bnode * btInsert(int x,Bnode * root) { Bnode *p,*q; int flag=0;

p=(Bnode *)malloc(sizeof(Bnode)); p->key=x;

p->right=p->left=NULL;

5 5

4mb07434d1797950lpza3sk4u09qt500fjq
领取福利

微信扫码领取福利

微信扫码分享