简单的数列排序

#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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值