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

2020-02-28 其他范文 下载本文

软件技术基础上机实验报告 顺序表由刀豆文库小编整理,希望给你工作、学习、生活带来方便,猜你可能喜欢“软件技术基础实验报告”。

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

姓名:肖燕平 上机实验 一 Ex1_1 #include #define maxnum 20

typedef struct list_type { int data[maxnum];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;i

scanf(“%d”,&k);

if(k==-1)

//输入-1则结束

break;

学号:2011019090028

}

} table->data[i]=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

printf(“NO DATA”);

creatlist(table);

}

for(i=0;ilength;i++){

printf(“%d

”,table->data[i]);} 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;i>pla-1;i--)

{

table->data[i+1]=table->data[i];

}

table->data[pla]=num;

table->length=table->length+2;

}

void delete_list(list_type *table,int place)

//删除一个数

{ int i;while(place>table->length-1||place

error(1);

printf(“nplease input the place of the delete number againn”);

scanf(“%d”,&place);

} for(i=place-1;ilength-1;i++){

table->data[i]=table->data[i+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,对于删除许多数时(例如把负数全部删除),要避免一次又一次的调用删除函数,防止出错。用x,y。Y首先比x前一位,若想

9,编程时,不要一来就写代码,一定要明确自己的步骤,在纸上写下来,用框图画好再写程序。

10,在有的方法总走不通时回头看是不是自己把问题复杂化了。

《软件技术基础上机实验报告 顺序表.docx》
将本文的Word文档下载,方便收藏和打印
推荐度:
软件技术基础上机实验报告 顺序表
点击下载文档
相关专题 软件技术基础实验报告 实验报告 软件技术 顺序 软件技术基础实验报告 实验报告 软件技术 顺序
[其他范文]相关推荐
    [其他范文]热门文章
      下载全文