软件技术基础上机实验报告 顺序表.doc_第1页
软件技术基础上机实验报告 顺序表.doc_第2页
软件技术基础上机实验报告 顺序表.doc_第3页
软件技术基础上机实验报告 顺序表.doc_第4页
软件技术基础上机实验报告 顺序表.doc_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

软件技术基础上机实验报告姓名:肖燕平学号:2011019090028上机实验 一Ex1_1#include#define maxnum 20 typedef struct list_typeint datamaxnum;int length;list_type;void error(int a)switch(a)case 0:printf(nthe length of the data is too longn);break;case 1:printf(nthe place is wrongn);break;void creatlist( list_type *table)/创建链表 int i;int k;table-length=0;printf(nplease input the numbers of the datan);for(i=0;idatai=k;table-length+;while(k!=-1)/如果数据输入过长,则报错且重新输入数据 error(0);while(k!=-1)/防止接下来的程序变量得到错误的数据 scanf(%d,&k);creatlist(table);void showlist(list_type *table)/显示数据 int i;while(table-length=0)printf(NO DATA);creatlist(table);for(i=0;ilength;i+)printf(%d ,table-datai);printf(nthe length of the data is %dn,table-length);void insertlist(list_type *table,int pla,int num)/插入一个数 int i;while(platable-length)/如果插入的位置不符合条件,则重新输入 error(1);printf(nplease input the place of the insert number againn);scanf(%d,&pla);table-length=table-length-1;pla=pla-1;for(i=table-length;ipla-1;i-)table-datai+1=table-datai;table-datapla=num;table-length=table-length+2;void delete_list(list_type *table,int place)/删除一个数 int i;while(placetable-length-1|place1)error(1);printf(nplease input the place of the delete number againn);scanf(%d,&place);for(i=place-1;ilength-1;i+)table-datai=table-datai+1;table-length-;void main()int inse_place,inse_num;int del_place;list_type table;creatlist(&table);/创建顺序表 showlist(&table);/显示顺序表 printf(nplease input the insert place and numbern);scanf(%d%d,&inse_place,&inse_num);insertlist(&table,inse_place,inse_num);/插入一个数 printf(nthe new list isn);showlist(&table);/显示插入数后的顺序表 printf(nplease input the delete placen);scanf(%d,&del_place);delete_list(&table,del_place);/删除一个数 printf(nthe new list isn);showlist(&table);输出数据:1,不考虑边界情况2,考虑边界问题及解决方法问题1:遗漏了某个变量而直接用注意:对于变量,要那个变量则再来定义,定义后再用。问题2:输入数据量大于19时,其余数字会赋给后程序的scanf。解决方法:利用另一变量k值,若k不等于-1则不允许程序往下走。问题3:在print“NO DATA”后,程序依然往下走,不能重新录入数据。解决方法:再调用输入数据函数,并且惯用while.问题还有很多,但忘了些。心得体会:1,在使用变量时,将要用哪个马上定义再使用。2,error函数尽量写在所有函数之前。方便任一函数调用。3,对于printf函数,多用换行。4,用scanf函数时,若输入数的量大于某一scanf的需求量,则要运用一函数消耗掉多余量,避免影响下面的函数,赋错值。5,对于一些不符合要求的录入值,要习惯于重新调用输入函数或调用自我重新录入。6,虽然自我的思考很重要,但还是要和同学讨论和交流算法。7,对于取值检验时,不能只取一种类型的数值或只随机取值,要注意取边界值和范围之外的值。8,对于删除许多数时(例如把负数全部删除),要避免一次又一次的调用删除函数,防止出错。用

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论