简单的数列排序

来源:互联网 发布:网络订餐食品安全现状 编辑:程序博客网 时间:2024/05/01 11:21
#include<stdio.h>
void menu(){

printf("1.input a new list\n");
printf("2.output my list\n");
printf("3.insert\n");
printf("4.delete\n");
printf("0.quit\n");
}
void main(){
int list[100];
int length;
int temp,i;
int pos,newnum,choice;
char c;
menu();
printf("please choice\n");
scanf("%d",&choice);
while(choice != 0){
switch(choice){
case 1:
printf("please input your length (max :100)\n");
scanf("%d",&length);
printf("please input %d numbers?\n",length);
i =0;
while(i<length){
scanf("%d",&list[i]);
i++;
}
break;
case 2:
if(length<0){
printf("please input a biao first");
break;
}else{
printf("your list :\n");
i=0;
while(i<length){
printf("%d",list[i]);
i++;
}
break;}
case 3:
if(length<0){
printf("please en 1 input a biao");
break;
}else{
printf("please your position\n");
scanf("%d",&pos);
printf("please insert new number \n");
scanf("%d",&newnum);
while(pos<1 || pos >length+1){
printf("wrong position ,please inout again\n");
scanf("%d",&pos);
}
if(pos>0 || pos<length){
while(i>pos){
list[i+1]=list[i];
i--;
}
list[pos-1]=newnum;
length++;
}
}
break;
case 4:
if(length<0){
printf("please input a biao first");
break;
}else{
printf("please input you want to delete position\n");
scanf("%d",&pos);
while(pos<1 || pos >length+1){
printf("wrong position ,please inout again\n");
scanf("%d",&pos);
}
for(i=pos;i<length;i++){
list[i-1]=list[i];
}
length--;
break;
}}
printf("\n");
menu();
scanf("%d",&choice);
}
}



1 0
原创粉丝点击