线性表基本操作 实验报告
院 系: 计算机科学学院
专 业: 计算机科学与技术
年 级:
课程名称: 数据结构
学 号:
姓 名:
指导教师:
2011年 03 月 26 日
年级?班号?学号?专业计算机科学与技术?姓名实验名称?线性表基本操作实验
类型设计型综合型创新型YES实
验
目
的
或
要
求?目的:实现线性表基本操作
要求:1、实现线性表的插入,删除,求表长,查找e元素的前驱、后继,查找第i个位置的元素等基本操作。
2、程序以菜单方式工作,其中一个选项控制退出程序,其他选项可循环进行选择。实
验
记
录实验源代码:
#include
#include
#include
typedef struct
{
int num;
char name[20];
int age;
}student;
typedef struct
{
student *elem;
int len;
int maxsize;
}sqlist;
void InitList_Sq(sqlist &L)
{
L.elem=(student*)malloc(100*sizeof(student));
L.len=0;
L.maxsize=100;
}
?
?
?
?
?
?
?
?
?
?
?
?
?
?
(写不完时,可另加附页。)实
验
记
录?
?int ListInsert_Sq(sqlist &L)
{
char con='y';
int i=0;
while((con=='y')||(con=='Y'))
{
if(L.len<100)
{
printf("Number:");
scanf("%d",&L.elem[i].num);
printf("Name:");
scanf("%s",L.elem[i].name);
printf("Age:");
scanf("%d",&L.elem[i].age);
i++;
L.len++;
printf("Do you want to contiune?(Y/N)");
getchar();
scanf("%s",&con);
while((con!='y')&&(con!='Y')&&(con!='N')&&(con!='n'))
{
printf("you can not choice but'y'and'n',please choice again!");
getchar();
scanf("%s",&con);
}
}
else
con='n';
}
return 1;
}
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
(写不完时,可另加附页。)实
验
记
录?
?int output_sq(sqlist &L)
{
int j;
for(j=0;j<=(L.len-1);j++)
{
printf("Number:%d\n",L.elem[j].num);
printf("Name:%s\n",L.elem[j].name);
printf("age:%d\n\n",L.elem[j].age);
}
return 1;
}
int getelem(sqlist L)
{
int i;
printf("Which one do you want to getelem?");
scanf("%d",&i);
i=i-1;
printf("Number:%d\n",L.elem[i].num);
printf("Name:%s\n",L.elem[i].name);
printf("age:%d\n\n",L.elem[i].age);
return 1;
}
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
(写不完时,可另加附页。)实
验
记
录?
?void insert(sqlist &L)
{
int i,j;
printf("before which place do you want to insert?");