资源描述:
《数据结构 线性表的 应用》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、《数据结构》实验报告实验一、线性表的应用-5-一、实验目的熟练掌握线性表的顺序存储结构和链式存储结构的建立方法以及基本操作算法,并根据实际问题的要求,灵活运用。二、实验内容本次实验要求以班级学生信息作为管理对象,通过实验练习,建立班级学生信息线性表的顺序存储结构和链式存储结构,并练习使用顺序表和单链表的基本操作算法,实现对班级学生信息的管理,包括学生信息的插入、学生信息的删除、学生信息的查询和学生信息线性表的输出。三、完成情况#include"stdio.h"#include"malloc.h"#defineNULL0structstu
2、dent{charname[20];chargender[8];intnum;intscore;structstudent*next;};intn;structstudent*head;structstudent*creat(){structstudent*p,*q;inta;n=0;p=q=(structstudent*)malloc(sizeof(structstudent));printf("请输入学生信息,按学号,姓名,性别,成绩:");scanf("%d%s%s%d",&p->num,p->name,p->gender,&
3、p->score);head=NULL;while(p->num!=0){n+=1;if(n==1)head=p;elseq->next=p;q=p;p=(structstudent*)malloc(sizeof(structstudent));printf("请输入学生信息,按学号,姓名,性别,成绩:");scanf("%d%s%s%d",&p->num,p->name,p->gender,&p->score);}printf("完成,按'1'结束");scanf("%d",&a);if(a){q->next=NULL;ret
4、urn(head);}-5-}voidprint(structstudent*head){inti;structstudent*p;printf("学号(8)姓名(8)性别成绩");printf("-------------------------------------------");printf("学号,姓名,性别,成绩:");p=head;for(i=0;inum,p->name,p->gender,p->sco
5、re);printf("-------------------------------------------");p=p->next;}}voidsearch(structstudent*head,intnumber){structstudent*p;p=head;while(p->num!=number){p=p->next;if(p==NULL)printf("学生信息不存在!");else{printf("该生的信息是:");printf("%d%s%s%d",p->num,p->name,p->gender,p
6、->score);}}}structstudent*insert(structstudent*head,inti){structstudent*p,*q,*r;inta;p=head;r=(structstudent*)malloc(sizeof(structstudent));if(i=n+1){while(p->next!=NULL)p=p->next;p->next=r;r->next=NULL;n+=1;return(head);}elseif(i<=n){for(a=0;anext;q=p-1;q-
7、>next=r;r->next=p;n+=1;printf("完成");return(head);}elseprintf("空间不足!");}-5-structstudent*del(structstudent*head,intnumber){structstudent*p,*q;p=head;while(p->num!=number)p=p->next;if(p==NULL)printf("该生不存在");else{q=p-1;q->next=p->next;free(p);printf("完成");n-=1;return
8、(head);}}voidmain(){inta,sn,dn,location;printf("学生信息管理系统");printf("================================