欢迎来到天天文库
浏览记录
ID:6686554
大小:356.00 KB
页数:20页
时间:2018-01-22
《[理科实验报告精品]线性表基本操作 实验报告》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、院系:计算机科学学院专业:计算机科学与技术年级:课程名称:数据结构学号:姓名:指导教师:2011年03月26日年级 班号 学号 专业计算机科学与技术 姓名实验名称 线性表基本操作实验类型设计型综合型创新型YES实验目的或要求 目的:实现线性表基本操作要求:1、实现线性表的插入,删除,求表长,查找e元素的前驱、后继,查找第i个位置的元素等基本操作。2、程序以菜单方式工作,其中一个选项控制退出程序,其他选项可循环进行选择。实验记录实验源代码:#include#include2、h>#includetypedefstruct{intnum;charname[20];intage;}student;typedefstruct{student*elem;intlen;intmaxsize;}sqlist;voidInitList_Sq(sqlist&L){L.elem=(student*)malloc(100*sizeof(student));L.len=0;L.maxsize=100;} (写不完时,可另加附页。)实验记录 intL3、istInsert_Sq(sqlist&L){charcon='y';inti=0;while((con=='y')4、5、(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("Doyouwanttocontiun6、e?(Y/N)");getchar();scanf("%s",&con);while((con!='y')&&(con!='Y')&&(con!='N')&&(con!='n')){printf("youcannotchoicebut'y'and'n',pleasechoiceagain!");getchar();scanf("%s",&con);}}elsecon='n';}return1;} (写不完时,可另加附页。)实验记录 intoutput_sq(sql7、ist&L){intj;for(j=0;j<=(L.len-1);j++){printf("Number:%d",L.elem[j].num);printf("Name:%s",L.elem[j].name);printf("age:%d",L.elem[j].age);}return1;}intgetelem(sqlistL){inti;printf("Whichonedoyouwanttogetelem?");scanf("%d",&i);i=i-1;printf("Number:%8、d",L.elem[i].num);printf("Name:%s",L.elem[i].name);printf("age:%d",L.elem[i].age);return1;} (写不完时,可另加附页。)实验记录 voidinsert(sqlist&L){inti,j;printf("beforewhichplacedoyouwanttoinsert?");scanf("%d",&i);for(j=(L.len-1);j>i-2;j--)L.9、elem[j+1]=L.elem[j];printf("Number:");scanf("%d",&L.elem[i-1].num);printf("Name:");scanf("%s",L.elem[i-1].name);printf("Age:");scanf("%d",&L.elem[i-1].age);L.len++;}voidlistdelete(sqlist&L){inti,j;printf("whichplacedoyouwanttodelete?");scanf("%d",&i);for10、(j=i;j
2、h>#includetypedefstruct{intnum;charname[20];intage;}student;typedefstruct{student*elem;intlen;intmaxsize;}sqlist;voidInitList_Sq(sqlist&L){L.elem=(student*)malloc(100*sizeof(student));L.len=0;L.maxsize=100;} (写不完时,可另加附页。)实验记录 intL
3、istInsert_Sq(sqlist&L){charcon='y';inti=0;while((con=='y')
4、
5、(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("Doyouwanttocontiun
6、e?(Y/N)");getchar();scanf("%s",&con);while((con!='y')&&(con!='Y')&&(con!='N')&&(con!='n')){printf("youcannotchoicebut'y'and'n',pleasechoiceagain!");getchar();scanf("%s",&con);}}elsecon='n';}return1;} (写不完时,可另加附页。)实验记录 intoutput_sq(sql
7、ist&L){intj;for(j=0;j<=(L.len-1);j++){printf("Number:%d",L.elem[j].num);printf("Name:%s",L.elem[j].name);printf("age:%d",L.elem[j].age);}return1;}intgetelem(sqlistL){inti;printf("Whichonedoyouwanttogetelem?");scanf("%d",&i);i=i-1;printf("Number:%
8、d",L.elem[i].num);printf("Name:%s",L.elem[i].name);printf("age:%d",L.elem[i].age);return1;} (写不完时,可另加附页。)实验记录 voidinsert(sqlist&L){inti,j;printf("beforewhichplacedoyouwanttoinsert?");scanf("%d",&i);for(j=(L.len-1);j>i-2;j--)L.
9、elem[j+1]=L.elem[j];printf("Number:");scanf("%d",&L.elem[i-1].num);printf("Name:");scanf("%s",L.elem[i-1].name);printf("Age:");scanf("%d",&L.elem[i-1].age);L.len++;}voidlistdelete(sqlist&L){inti,j;printf("whichplacedoyouwanttodelete?");scanf("%d",&i);for
10、(j=i;j
此文档下载收益归作者所有