顺序表的应用-数据结构实验报告Word文档格式.docx
《顺序表的应用-数据结构实验报告Word文档格式.docx》由会员分享,可在线阅读,更多相关《顺序表的应用-数据结构实验报告Word文档格式.docx(9页珍藏版)》请在冰豆网上搜索。
(3)根据姓名进行查找,返回此学生的学号和成绩
(4)根据指定的位置可返回相应的学生信息(学号,姓名,成绩)
(5)给定一个学生信息,插入到表中指定的位置
(6)删除指定位置的学生记录
(7)统计表中学生个数
四、实验设计
for(count=0;
count<
n;
count++)
{
scanf("
%s%s%d"
e.no,e.name,&
e.score);
Input(&
L,e);
}
StatusInput(SqList*L,ElemTypee)
if(!
(*L).elem)
returnERROR;
(*L).elem[(*L).length++]=e;
returnOK;
StatusPrint(SqListL)
printf("
学号姓名成绩\n"
);
intcount;
for(count=0;
L.length;
Pri(L.elem[count]);
voidPri(ElemTypee)
printf("
%8s|"
e.no);
printf("
%20s|"
e.name);
%8d\n"
e.score);
StatusLocateElem(SqListL,ElemTypee)
if(strcmp(L.elem[count].name,e.name)==0)
break;
if(count<
L.length)
{
Pri(L.elem[count]);
}
else
%s在顺序表中查不到!
\n"
StatusLocateNum(SqListL,inti)
if(i<
1||i>
L.length+1)
returnOVERFLOW;
Pri(L.elem[i-1]);
StatusListInsert(SqList*L,inti,ElemTypee)
if(i<
(*L).length+1)
if((*L).length==(*L).MaxSize)
(*L).elem=(ElemType*)realloc((*L).elem,sizeof(ElemType)*((*L).MaxSize+LISTINCREMENT));
exit(OVERFLOW);
for(count=(*L).length-1;
count>
=i-1;
count--)
(*L).elem[count+1]=(*L).elem[count];
(*L).elem[i-1]=e;
(*L).length++;
StatusListDelete(SqList*L,inti)
for(count=i;
(*L).length;
(*L).elem[count-1]=(*L).elem[count];
(*L).length--;
printf("
表中学生的个数为:
%d\n"
L.length);
(8)主函数
intmain()
SqListL;
ElemTypee;
inti,count,n,number;
InitList(&
L);
请输入学生的个数:
%d"
&
n);
请输入学号、姓名、成绩:
scanf("
Input(&
学生信息生成成功!
Pr();
while(n>
0&
&
n<
7)
switch(n)
{
case1:
Print(L);
case2:
请输入要查找的学生的姓名:
"
scanf("
%s"
LocateElem(L,e);
case3:
请输入要查找的学生的位置:
i);
LocateNum(L,i);
case4:
输入插入学生的位置、学号、姓名、成绩:
%d%s%s%d"
i,e.no,e.name,&
if(ListInsert(&
L,i,e))
printf("
插入成功!
case5:
请输入要删除的学生的位置:
if(ListDelete(&
L,i))
删除成功!
case6:
}
Pr();
if(n==7)
退出成功!
return0;
五、实验测试
2.定义一个包含学生信息(学号,姓名,成绩)的顺序表,使其具有如下功能运行界面
六、总结
附录1:
源代码
#include<
stdio.h>
stdlib.h>
string.h>
#defineLIST_INIT_SIZE100
#defineLISTINCREMENT10
#defineOK1
#defineERROR0
#defineOVERFLOW2
typedefintStatus;
typedefstruct
charno[8];
charname[20];
intscore;
}Student;
typedefStudentElemType;
ElemType*elem;
intlength;
intMaxSize;
}SqList;
StatusInitList(SqList*L)
(*L).elem=(ElemType*)malloc(sizeof(ElemType)*LIST_INIT_SIZE);
(*L).length=0;
(*L).MaxSize=LIST_INIT_SIZE;
(*L).elem=(ElemType*)realloc((*L).elem,sizeof(El