欢迎来到天天文库
浏览记录
ID:52141401
大小:121.00 KB
页数:7页
时间:2020-03-23
《软件技术基础上机实验报告_顺序表.doc》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、软件技术基础上机实验报告姓名:肖燕平学号:2011019090028上机实验一Exl_l#include#definemaxnum20typedefstructlist_type{intdata[maxnum];intlength;}list_type;voiderror(inta){switch(a){case0:printf「thelengthofthedataistoolongH);break;case1:printfC^ntheplaceiswrong'n”);break;}}voidcreatlist(list_type*table)〃创建链表{inti;
2、intk;table->length=O;printf(HpleaseinputthenumbersofthedataH);for(i=0;idata[i]=k;table->length++;}while(k!=-l)〃如果数据输入过长,则报错且重新输入数据{error(O);while(k!=-l)〃防止接下来的程序变量得到错误的数据{scanf(”%d”,&k);}creatlist(table);}}voidshowlist(list_type*table)〃显
3、示数据{inti;while(table->length<=O){printf("NODATA");creatlist(table);}for(i=0;ilength;i++){printf("%d",table->data[i]);}printf("thelengthofthedatais%d"ztable->length);}voidinsertlist(list_type*table,intplazintnum)//插入一个数{inti;while(pla<011pla>table->length)//如果插入的位置不符合条件,则重新输入error(l);pri
4、ntfC'npleaseinputtheplaceoftheinsertnumberagain");scanf(”%d”,&pla);}table->length=table->length-l;pla=pla-l;for(i=table->length;i>pla-l;i-){table->data[i+l]=table->data[i];}table->data[pla]=num;table->length=table・>length+2;}voiddelete」ist(list_type*table,intplace)〃删除一个数{inti;while(place>table->l
5、ength-l11placelength-l;i++){table->data[i]=table->data[i+l];}table->length~;}voidmain(){intinse_placejnse_num;intdel_place;list_typetable;creatlist(&table);〃创建顺序表showlist(&table);〃显示顺序表p
6、rintf(HpleaseinputtheinsertplaceandnumberrV');scanf(H%d%dH/&inse_place/&inse_num);insertlist(&table,inse_place,inse_num);〃插入一个数printf(HthenewlistisM);showlist(&table);//显示插入数后的顺序表printf(Hpleaseinputthedeleteplace”);scanf("%d",&del_place);delete_list(&table,del_place);〃删除一个数printf("then
7、ewlistis");showlist(&table);输出数据:1,不考虑边界情况■飞:欢件技朮基亡完戒誌.朕序表的豆入与5]涂'liaodan.ex*pleaseinputthenumbersofthedata12-34567-8-90-112-34567-8-90thelengthofthedatais10pleaseinputtheinsertplaceandnunber48thenewlist
此文档下载收益归作者所有