1、数据结构实验报告实验一、线性表的应用 - 1 -一、实验目的 熟练掌握线性表的顺序存储结构和链式存储结构的建立方法以及基本操作算法,并根据实际问题的要求,灵活运用。二、实验内容本次实验要求以班级学生信息作为管理对象,通过实验练习,建立班级学生信息线性表的顺序存储结构和链式存储结构,并练习使用顺序表和单链表的基本操作算法,实现对班级学生信息的管理,包括学生信息的插入、学生信息的删除、学生信息的查询和学生信息线性表的输出。三、完成情况 #include “stdio.h“#include “malloc.h“#define NULL 0struct studentchar name20;char
2、gender8;int num;int score;struct student *next;int n;struct student *head;struct student *creat()struct student *p,*q;int a;n=0;p=q=(struct student *)malloc(sizeof(struct student);printf(“请输入学生信息,按学号,姓名,性别,成绩:n“);scanf(“%d%s%s%d“,head=NULL;while(p-num!=0)n+=1;if(n=1) head=p;else q-next=p;q=p;p=(stru
3、ct student *)malloc(sizeof(struct student);printf(“请输入学生信息,按学号,姓名,性别,成绩:n“);scanf(“%d%s%s%d“,printf(“完成,按1结束n“);scanf(“%d“,if(a)q-next=NULL; return(head);- 2 -void print(struct student *head)int i;struct student *p;printf(“n 学号(8) 姓名(8) 性别 成绩n“);printf(“-n“);printf(“学号,姓名,性别,成绩:n “);p=head;for(i=0;i
4、num,p-name,p-gender,p-score);printf(“-n“);p=p-next;void search(struct student *head,int number)struct student *p;p=head;while (p-num!=number)p=p-next;if(p=NULL)printf(“学生信息不存在!n“);elseprintf(“该生的信息是 :n“);printf(“%d%s%s%dn“,p-num,p-name,p-gender,p-score); struct student *insert(struct student *head,i
5、nt i)struct student *p,*q,*r;int a;p=head;r=(struct student *)malloc(sizeof(struct student);if(i=n+1)while(p-next!=NULL)p=p-next;p-next=r;r-next=NULL;n+=1;return (head);else if(inext;q=p-1;q-next=r;r-next=p;n+=1;printf(“完成n“);return (head);else printf(“空间不足!n“);- 3 -struct student *del(struct studen
6、t *head,int number)struct student *p,*q;p=head;while (p-num!=number) p=p-next;if (p=NULL) printf(“该生不存在n“);elseq=p-1;q-next=p-next;free(p);printf(“完成“);n-=1;return (head);void main()int a,sn,dn,location;printf(“n 学生信息管理系统n“);printf(“=n“);printf(“ 1.学生信息线性表的建立n“);printf(“ 2.插 入 学 生 信 息n“);printf(“ 3.
7、查 询 学 生 信 息n“);printf(“ 4.删 除 学 生 信 息n“);printf(“ 5.输 出 所有学生信息n“);printf(“ 0.退 出 管 理 系 统n“);printf(“=n“);printf(“请选择 0-5:n“);scanf(“%d“,switch(a)case 1:head=creat();break;case 2:printf(“添加学生信息n“);printf(“请输入要添加的学生信息,按学号、姓名、性别、成绩:n“);scanf(“%d“,head=insert(head,location);break;case 3:printf(“请输入学生学号
8、n“);scanf(“%d“,search(head,sn);break;case 4:printf(“请输入学生学号 n“);scanf(“%d“,head=del(head,dn);break;case 5:print(head);break;case 0:printf(“再见n“);break;四、实验结果 - 4 -五、问题与解决程序执行窗口执行完成后,自动关闭窗口,用户无法观察信息,于是手动添加了语句来实现人工结束窗口,第一次加到了 return 前,发现执行后没有起到作用,遂改为 return 前。六、思考题七、实验总结 程序执行过程中遇到 return 则直接返回,不执行剩余部分
9、。该程序只是线性表创建、插入、删除等简单操作练习,没有基于数据写入,所以基本上这个程序只是一个框- 5 -架,每部分都是独立的,随着知识的加深还可以改进此类程序。实验成绩评价项目 评分等 级独立完成完整的实验内容,结果完全正确,报告内容完整,排版整洁美观,能真实体现实际操作过程及遇到的问题。 A完成实验,实验内容较为完整,结果正确,报告内容较为完整,排版较为整洁美观,能体现实际操作过程及遇到的问题。 B基本完成实验,结果正确,报告内容欠缺,排版较为整洁美观,能体现实际操作过程及遇到的问题。 C不能独立完成完整的实验内容,结果不真实,报告内容欠缺,排版欠整洁美观,不能体现实际操作过程及遇到的问题。 D