软件技术基础上机实验报告 顺序表

软件技术基础上机实验报告 顺序表

ID:40957858

大小:160.00 KB

页数:7页

时间:2019-08-11

软件技术基础上机实验报告 顺序表_第1页
软件技术基础上机实验报告 顺序表_第2页
软件技术基础上机实验报告 顺序表_第3页
软件技术基础上机实验报告 顺序表_第4页
软件技术基础上机实验报告 顺序表_第5页
资源描述:

《软件技术基础上机实验报告 顺序表》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、软件技术基础上机实验报告姓名:肖燕平学号:2011019090028上机实验一Ex1_1#include#definemaxnum20typedefstructlist_type{intdata[maxnum];intlength;}list_type;voiderror(inta){switch(a){case0:printf("thelengthofthedataistoolong");break;case1:printf("theplaceiswrong");break;}}voidcreatlist

2、(list_type*table)//创建链表{inti;intk;table->length=0;printf("pleaseinputthenumbersofthedata");for(i=0;idata[i]=k;table->length++;}while(k!=-1)//如果数据输入过长,则报错且重新输入数据{error(0);while(k!=-1)//防止接下来的程序变量得到错误的数据{scanf(

3、"%d",&k);}creatlist(table);}}voidshowlist(list_type*table)//显示数据{inti;while(table->length<=0){printf("NODATA");creatlist(table);}for(i=0;ilength;i++){printf("%d",table->data[i]);}printf("thelengthofthedatais%d",table->length);}voidinsertlist(list_type*table,int

4、pla,intnum)//插入一个数{inti;while(pla<0

5、

6、pla>table->length)//如果插入的位置不符合条件,则重新输入{error(1);printf("pleaseinputtheplaceoftheinsertnumberagain");scanf("%d",&pla);}table->length=table->length-1;pla=pla-1;for(i=table->length;i>pla-1;i--){table->data[i+1]=table->data[i];}table->d

7、ata[pla]=num;table->length=table->length+2;}voiddelete_list(list_type*table,intplace)//删除一个数{inti;while(place>table->length-1

8、

9、place<1){error(1);printf("pleaseinputtheplaceofthedeletenumberagain");scanf("%d",&place);}for(i=place-1;ilength-1;i++){table->data[i]=

10、table->data[i+1];}table->length--;}voidmain(){intinse_place,inse_num;intdel_place;list_typetable;creatlist(&table);//创建顺序表showlist(&table);//显示顺序表printf("pleaseinputtheinsertplaceandnumber");scanf("%d%d",&inse_place,&inse_num);insertlist(&table,inse_place,inse_num);//插

11、入一个数printf("thenewlistis");showlist(&table);//显示插入数后的顺序表printf("pleaseinputthedeleteplace");scanf("%d",&del_place);delete_list(&table,del_place);//删除一个数printf("thenewlistis");showlist(&table);}输出数据:1,不考虑边界情况2,考虑边界问题及解决方法问题1:遗漏了某个变量而直接用注意:对于变量,要那个变量则再来定义,定义后再用。问

12、题2:输入数据量大于19时,其余数字会赋给后程序的scanf。解决方法:利用另一变量k值,若k不等于-1则不允许程序往下走。问题3:在print“NODATA”后,程序依然往下走

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。