谁能帮我看下这个程序都有什么错误?错的地方能帮改一下吗?
答案:1 悬赏:60 手机版
解决时间 2021-01-09 22:47
- 提问者网友:谁的错
- 2021-01-09 19:49
谁能帮我看下这个程序都有什么错误?错的地方能帮改一下吗?
最佳答案
- 五星知识达人网友:野味小生
- 2021-01-09 21:23
编译已经通过,请看以下代码:
#include
#include "malloc.h"
#define MaxSize 100
#define elemtype int
struct SeqList
{
elemtype elem[MaxSize];
int length;
};
struct SeqList *SL;
void CreatList_Sq(struct SeqList *L)
{
int n,i;
#if 0
L = (struct SeqList *)malloc(sizeof(struct SeqList));
if (!L) printf("init failed");
L->length=0;
printf("init success\n");
printf("please input the number of array__element n:\n");
#endif
scanf("%d",&n);
printf("please input %d numbers:\n",n);
for (i=0;i {
scanf("%d",&L->elem[i]);
L->length++;
};
printf("\n");
}
void ListInsert_Sq (struct SeqList *L, int i, elemtype item)
{ int j;
if (i>L->length||L->length>MaxSize-1)
printf("insert failed") ;
for (j=L->length-1; j>=i ; j--)
L->elem[j+1] = L->elem[j];
L->elem[i] = item;
L->length++;
printf("insert success");
}
void ListDelete_Sq (struct SeqList *L, int i)
{ int j;
if (i>L->length-1||L->length==0)
printf("delete failed");
for (j=i+1; jlength; j++)
L->elem[j-1]=L->elem[j];
L->length--;
printf("delete success");
}
void show(struct SeqList *L)
{
int j;
printf("the array is :\n");
for (j=0;jlength;j++)
printf("%d ",L->elem[j]);
printf("\n");
}
main()
{
int num,delp,f=1;
int position,i;
int no;
clrscr();
while(f)
{ printf("no.1:creatlist\nno.2:insertlist\nno.3:deletlist\nno.0:exit\n");
scanf("%d",&no);
switch(no)
{
case 1: CreatList_Sq(SL); printf("length=%d",SL->length);
show(SL);
break;
case 2: printf("please point to the position you want to:\n");
scanf("%d",&position);
printf("Input the inserted number:\n");
scanf("%d",&num);
printf("\n");
ListInsert_Sq(SL,position,num);
show(SL);
break;
case 3: printf("Input the deleted the position of the number:");
scanf("%d",&delp);
printf("\n");
ListDelete_Sq(SL,delp);
show(SL);
break;
case 0: break;
}
printf("do you want to continue ?\nno.1:continue\nno.0:exit\n");
scanf("%d",&f);
}
}
#include
#include "malloc.h"
#define MaxSize 100
#define elemtype int
struct SeqList
{
elemtype elem[MaxSize];
int length;
};
struct SeqList *SL;
void CreatList_Sq(struct SeqList *L)
{
int n,i;
#if 0
L = (struct SeqList *)malloc(sizeof(struct SeqList));
if (!L) printf("init failed");
L->length=0;
printf("init success\n");
printf("please input the number of array__element n:\n");
#endif
scanf("%d",&n);
printf("please input %d numbers:\n",n);
for (i=0;i
scanf("%d",&L->elem[i]);
L->length++;
};
printf("\n");
}
void ListInsert_Sq (struct SeqList *L, int i, elemtype item)
{ int j;
if (i>L->length||L->length>MaxSize-1)
printf("insert failed") ;
for (j=L->length-1; j>=i ; j--)
L->elem[j+1] = L->elem[j];
L->elem[i] = item;
L->length++;
printf("insert success");
}
void ListDelete_Sq (struct SeqList *L, int i)
{ int j;
if (i>L->length-1||L->length==0)
printf("delete failed");
for (j=i+1; j
L->elem[j-1]=L->elem[j];
L->length--;
printf("delete success");
}
void show(struct SeqList *L)
{
int j;
printf("the array is :\n");
for (j=0;j
printf("%d ",L->elem[j]);
printf("\n");
}
main()
{
int num,delp,f=1;
int position,i;
int no;
clrscr();
while(f)
{ printf("no.1:creatlist\nno.2:insertlist\nno.3:deletlist\nno.0:exit\n");
scanf("%d",&no);
switch(no)
{
case 1: CreatList_Sq(SL); printf("length=%d",SL->length);
show(SL);
break;
case 2: printf("please point to the position you want to:\n");
scanf("%d",&position);
printf("Input the inserted number:\n");
scanf("%d",&num);
printf("\n");
ListInsert_Sq(SL,position,num);
show(SL);
break;
case 3: printf("Input the deleted the position of the number:");
scanf("%d",&delp);
printf("\n");
ListDelete_Sq(SL,delp);
show(SL);
break;
case 0: break;
}
printf("do you want to continue ?\nno.1:continue\nno.0:exit\n");
scanf("%d",&f);
}
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯