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

  • 5
  • 0
  • 约2.93千字
  • 约 7页
  • 2016-08-29 发布于重庆
  • 举报
软件技术基础上机实验报告顺序表

软件技术基础上机实验报告 姓名:肖燕平 学号:2011019090028 上机实验 一 Ex1_1 #includestdio.h #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 long\n);break; case 1: printf(\nthe place is wrong\n);break; } } void creatlist( list_type *table) //创建链表 { int i; int k; table-length=0; printf(\nplease input the numbers of the data\n); for(i=0;imaxnum-1;i++) { scanf(%d,k); if(k==-1) //输入-1则结束 break; 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=0) { printf(NO DATA); creatlist(table); } for(i=0;itable-length;i++) { printf(%d ,table-data[i]); } printf(\nthe length of the data is %d\n,table-length); } void insertlist(list_type *table,int pla,int num)//插入一个数 { int i; while(pla0||platable-length)//如果插入的位置不符合条件,则重新输入 { error(1); printf(\nplease input the place of the insert number again\n); scanf(%d,pla); } table-length=table-length-1; pla=pla-1; for(i=table-length;ipla-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(placetable-length-1||place1) { error(1); printf(\nplease input the place of the delete number again\n); scanf(%d,place); } for(i=place-1;itable-length-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 number\n); scanf(%d%d,inse_place,inse_num); insertlist(table,inse_place,inse_num); //插入一个数 printf(\nthe new list is\n);

文档评论(0)

1亿VIP精品文档

相关文档