欢迎来到天天文库
浏览记录
ID:10835567
大小:45.00 KB
页数:5页
时间:2018-07-08
《实验1、有序表的建立、插入与删除》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、实验一、有序表的建立、插入和删除一、实验目的:1、了解有序表的顺序存储结构。2、掌握有序表元素在内存中是怎么存储的。3、在有序表中实现如下操作:1)插入一个新元素到第i个位置,使原来标号为增一;2)删除第i个位置的元素;3)存一个新元素到第i个位置;4)读表;5)检索表中第i个元素;6)寻表的长度;二、实验步骤:1、参考实验程序自己编出的程序,上级调试。2、对调试好的程序进行以下实验:当机器显示表长时,可以渐入一个小于100的整数,然后根据功能表做:1:表示有序表的插入;2:表示有序表的删除;3:表示存新值;4:表示检
2、索第i个元素;5:表示查表长;三、参考程序:#includestaticintarray[100];intj,i,n,p;intch;voiddu(){printf("pleasetellmewhichnumberdoyouoperate:");scanf("%d",&i);while(i>n){printf("error,pleaseinputagain");scanf("%d",&i);}}voidda(){printf("thelistis");for(j=0;j3、4d",array[j]);printf("");}voidshow(){printf("-------------------");printf("thefunctionofthelist");printf("1:insert");printf("2:delete");printf("3:savenewelement");printf("4:readlist");printf("5:check");printf("6:thelengthofthelist");printf("0:e4、nd");printf("--------------------");}voidmain(){printf("pleaseinputthelengthoflist:");scanf("%d",&n);printf("");printf("pleaseentertheelements:");for(i=0;i=0&&p<=6){s5、witch(p){case1:printf("theinsertednumberplacesthefrontoftheoperation:");du();for(j=n-1;j>=i-1;j--)array[j+1]=array[j];printf("pleaseenternumber:");scanf("%d",&ch);array[i-1]=ch;n++;da();break;case2:du();for(j=i-1;j<=n;j++)array[j]=array[j+1];n--;da();break;cas6、e3:du();printf("pleaseenternewelement:");scanf("%d",&ch);printf("");array[i-1]=ch;da();break;case4:da();break;case5:du();printf("whatisthe%dnumber:",i);printf("%3d",array[i-1]);break;case6:printf("thelengthofthelistis:");printf("%3d",n);break;case0:p=0;b7、reak;}}}printf("error,pleaseenternewnumber");}四、运行结果:
3、4d",array[j]);printf("");}voidshow(){printf("-------------------");printf("thefunctionofthelist");printf("1:insert");printf("2:delete");printf("3:savenewelement");printf("4:readlist");printf("5:check");printf("6:thelengthofthelist");printf("0:e
4、nd");printf("--------------------");}voidmain(){printf("pleaseinputthelengthoflist:");scanf("%d",&n);printf("");printf("pleaseentertheelements:");for(i=0;i=0&&p<=6){s
5、witch(p){case1:printf("theinsertednumberplacesthefrontoftheoperation:");du();for(j=n-1;j>=i-1;j--)array[j+1]=array[j];printf("pleaseenternumber:");scanf("%d",&ch);array[i-1]=ch;n++;da();break;case2:du();for(j=i-1;j<=n;j++)array[j]=array[j+1];n--;da();break;cas
6、e3:du();printf("pleaseenternewelement:");scanf("%d",&ch);printf("");array[i-1]=ch;da();break;case4:da();break;case5:du();printf("whatisthe%dnumber:",i);printf("%3d",array[i-1]);break;case6:printf("thelengthofthelistis:");printf("%3d",n);break;case0:p=0;b
7、reak;}}}printf("error,pleaseenternewnumber");}四、运行结果:
此文档下载收益归作者所有