- 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);
您可能关注的文档
最近下载
- XX 磷酸铁锂(LFP)生产基地数字万用表(FLUKE 17B+)校准报告.docx VIP
- 油水分离器说明书ocean_clean_eb.pdf VIP
- 华能新能源山西分公司风电机组年度定检作业指导书.docx VIP
- (最新全套表格)SL631-2025年水利水电工程单元工程施工质量检验表与验收表.doc VIP
- 2025年教师资格证考试-中学教师资格证音乐(统考)考试近5年真题集锦(频考类试题)带答案.docx
- 2025年江苏城市职业学院单招笔试英语试题库含答案解析.docx VIP
- 电流表电压表功率表及电阻表检定规程试验报告.doc VIP
- 某建筑安装集团公司应急救援预案专项方案.docx VIP
- 移动基站用电安全培训课件.pptx VIP
- (高清版)DG∕TJ 08-202-2020 钻孔灌注桩施工标准.pdf VIP
原创力文档

文档评论(0)