main()
{
int j;
sqlist *l;
void initlist(sqlist *l);
void listinsert(sqlist *l,int i,int e);
initlist(l);
printf("please input your number:\n");
for(j=0;j
scanf("%d",l->a+j);
scanf("%d",&(l->length));
listinsert(l,4,100);
for(j=0;j
printf("%d ",l->a[j]);
}
void initlist(sqlist *l)
{
l->a=(int *)malloc(10*sizeof(int));
if(l->a==NULL)
{
printf("error");
exit(1);
}
l->length=0;
}
void listinsert(sqlist *l,int i,int e)
{
int *p,*q;
if(il->length+1)
printf("error");
l->a=(int *)realloc(l->a,(l->length+1)*sizeof(int));
if(l->a==NULL)
exit(1);
p=l->a+i;
for(q=l->a+l->length-1;p<=q;q--)
*(q+1)=*q;
*p=e;
l->length++;
}
不知道代码错在哪里?
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-