typedefstruct
{
int*elem;
intlength;
intlistsize;
}Sqlist;
statusCreate_sq(Sqlist*L,intn)
inti;
L->elem=(int*)malloc(100*sizeof(int));
if(!L->elem)return0;
for(i=0;i<n;i++)
scanf("%d",&(L->elem[i]));
L->length=n;
L->listsize=100;
return1;
}
statusListinsert_sq(Sqlist*L,inti,inte)
int*q,*p,*newbase;
if(i<1||i>L->length+1)return0;
if(L->length>=L->listsize)
newbase=(int*)realloc(L->elem,(L->listsize+10)*sizeof(int));
if(!newbase)exit(-2);
L->elem=newbase;
L->listsize+=10;
q=&(L->elem[i-1]);
for(p=&(L->elem[L->length-1]);p>=q;--p)
*(p+1)=*p;
*q=e;
++L->length;
intmain()
SqlistL1;
intn,a;
inti,e;
printf("\npleaseinputthenumberofdata:\n");
scanf("%d",&n);
if(Create_sq(&L1,n)==1)
scanf("%d%d",&i,&e);
a=Listinsert_sq(&L1,i,e);
if(a==1)
printf("insertsuccess\n");
elseprintf("insertfalse\n");
printf("thelistelementsare:\n");
for(i=1;i<=L1.length;i++)
printf("%d\t",L1.elem[i-1]);
return0;
typedefstruct
{
int*elem;
intlength;
intlistsize;
}Sqlist;
statusCreate_sq(Sqlist*L,intn)
{
inti;
L->elem=(int*)malloc(100*sizeof(int));
if(!L->elem)return0;
for(i=0;i<n;i++)
scanf("%d",&(L->elem[i]));
L->length=n;
L->listsize=100;
return1;
}
statusListinsert_sq(Sqlist*L,inti,inte)
{
int*q,*p,*newbase;
if(i<1||i>L->length+1)return0;
if(L->length>=L->listsize)
{
newbase=(int*)realloc(L->elem,(L->listsize+10)*sizeof(int));
if(!newbase)exit(-2);
L->elem=newbase;
L->listsize+=10;
}
q=&(L->elem[i-1]);
for(p=&(L->elem[L->length-1]);p>=q;--p)
*(p+1)=*p;
*q=e;
++L->length;
return1;
}
intmain()
{
SqlistL1;
intn,a;
inti,e;
printf("\npleaseinputthenumberofdata:\n");
scanf("%d",&n);
if(Create_sq(&L1,n)==1)
{
scanf("%d%d",&i,&e);
a=Listinsert_sq(&L1,i,e);
if(a==1)
printf("insertsuccess\n");
elseprintf("insertfalse\n");
printf("thelistelementsare:\n");
for(i=1;i<=L1.length;i++)
{
printf("%d\t",L1.elem[i-1]);
}
}
return0;
}