欢迎来到天天文库
浏览记录
ID:30932987
大小:592.24 KB
页数:24页
时间:2019-01-04
《西安电子科技大学自考数据结构实验报告》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、《数据结构》实践考核报告专业:计算机及应用准考证号:姓名:考点:西安电子科技大学考试时间:2009-5-25一、实验目的上机考核实践考核检测对数据结构该课程掌握的程度,消化课程内容,加深理解数据结构的基础概念、基木理论和基木方法。二、实验环境1.硬件:CPUP42.4G内存:256M硬盘:40.G2.软件:VC++三、实验考核内容单元一:线形数据结构上的基本运算描述及实现。(1)顺序表上基本算法的运算描述及实现。#defineListSize100typcdefintDataTypc;typedefstruet{DataTypedata[ListSi
2、ze];intlength;}SepList;voidSet(SepList*L){L->length=0;}voidInsertList(SepList*L,DeitaTypex,inti){intj;辻(i3、4、i>L->length+l)Error(,zpositionerror,z);if(L->length>二ListSize)Error("overflow");for(j=L->length-l;i>=i~l;j--)L->data[j+l]=L->data[j];L->data[i-l]=x;L->length++;}voidCove5、rs(ScpList*L){inti;DataTypetemp;for(i=0;ilength/2;i++){temp=L~>data[i];L->data[i]=L->data[L->length-i-l];L->data[L->length-i-l]=temp;}voidOut(SepList*L){inti;for(i=0;i〈Length;i++)printf(,z%d〃,L->data[i]);}main(){intx,i,y=0;charch二〃A〃Seqlist*L;set(L);while(y!=5){printf("choi6、cenum:1:iscreatelist:2:isinsertlist:〃)printf(,z3:isdeletelist:4:isCoverslist:rT);printf(〃5:isend:〃);scanf("%d",&y);if(y==l){printf("crceitalistandinputinitdata:,z)scanf&y);L->length二x;for(i=0;idatei[i]二x;}printf(〃listis:〃);0ut(L);printf(〃rT7、);elseif(y==2){printf(,zinputdatainsertandpositioni:〃);seanf(〃%d〃,&x);seanf(〃%d〃,&i);InsertList(L,x,i);0ut(L);printf("");}elseif(y==3){printf("inputdeleteposition:〃);scanf&x);DeleteList(L,x);0ut(L);printf(〃rT);}elseif(y=4){printf(〃conversis:〃);Convers(L);Out(L);}elseif(y=5)e8、xit(0);scanf(〃%d",&y);}}(2)单链表上基本算法的运算描述及实现。#include"stdio.h〃ttinclude"stdlib.h〃ttdefinenull0struetstu{chardata;struetstu*next;};main()/*主函数*/{intx,xl;charch;struetstu*head,*p,*s,*q,*h,*7;printfC现在开始建立链表・・・・请输入字符:〃);/*开始建立链表*/head=(structstu*)malloc(sizeof(structstu));p二head;9、p~>next二nul1;ch=gctchar();while(ch!=,){s=(structstu*)malloc(sizeof(structstu));s->data二ch;p->next=s;P=S;p->next二null;ch=getchar();}/*建立后输出*/printfC建立后的链表为:〃);p=hcad;output(p->next);p=head;aa:printf(〃〃);printf(〃***************************〃);*『);*〃);*r);*『);*r);*『)10、;*〃);*r);*〃);printf(〃*printf(〃*printf(〃*1.插入2.删除p
3、
4、i>L->length+l)Error(,zpositionerror,z);if(L->length>二ListSize)Error("overflow");for(j=L->length-l;i>=i~l;j--)L->data[j+l]=L->data[j];L->data[i-l]=x;L->length++;}voidCove
5、rs(ScpList*L){inti;DataTypetemp;for(i=0;ilength/2;i++){temp=L~>data[i];L->data[i]=L->data[L->length-i-l];L->data[L->length-i-l]=temp;}voidOut(SepList*L){inti;for(i=0;i〈Length;i++)printf(,z%d〃,L->data[i]);}main(){intx,i,y=0;charch二〃A〃Seqlist*L;set(L);while(y!=5){printf("choi
6、cenum:1:iscreatelist:2:isinsertlist:〃)printf(,z3:isdeletelist:4:isCoverslist:rT);printf(〃5:isend:〃);scanf("%d",&y);if(y==l){printf("crceitalistandinputinitdata:,z)scanf&y);L->length二x;for(i=0;idatei[i]二x;}printf(〃listis:〃);0ut(L);printf(〃rT
7、);elseif(y==2){printf(,zinputdatainsertandpositioni:〃);seanf(〃%d〃,&x);seanf(〃%d〃,&i);InsertList(L,x,i);0ut(L);printf("");}elseif(y==3){printf("inputdeleteposition:〃);scanf&x);DeleteList(L,x);0ut(L);printf(〃rT);}elseif(y=4){printf(〃conversis:〃);Convers(L);Out(L);}elseif(y=5)e
8、xit(0);scanf(〃%d",&y);}}(2)单链表上基本算法的运算描述及实现。#include"stdio.h〃ttinclude"stdlib.h〃ttdefinenull0struetstu{chardata;struetstu*next;};main()/*主函数*/{intx,xl;charch;struetstu*head,*p,*s,*q,*h,*7;printfC现在开始建立链表・・・・请输入字符:〃);/*开始建立链表*/head=(structstu*)malloc(sizeof(structstu));p二head;
9、p~>next二nul1;ch=gctchar();while(ch!=,){s=(structstu*)malloc(sizeof(structstu));s->data二ch;p->next=s;P=S;p->next二null;ch=getchar();}/*建立后输出*/printfC建立后的链表为:〃);p=hcad;output(p->next);p=head;aa:printf(〃〃);printf(〃***************************〃);*『);*〃);*r);*『);*r);*『)
10、;*〃);*r);*〃);printf(〃*printf(〃*printf(〃*1.插入2.删除p
此文档下载收益归作者所有