直接定义静态数组方式
#include <stdio.h>
#include <stdlib.h>
#define MAXSIZE 1000
typedef int elemtype;
typedef struct
{
elemtype elem[MAXSIZE];
int last;
}seqlist;
void Initlist(seqlist l)
{
l.last=0;
}
int Inslist(seqlist l,int i,elemtype e)
{
int k;
if((i<1)||(i>l.last+1))
{
printf("插入位置不合法");
}
for(k=l.last;k>=i-1;k--)
l.elem[k+1]=l.elem[k];
l.elem[i-1]=e;
l.last++;
for(k=0;k<l.last-1;k++)
printf("%d\t",l.elem[k]);
}
int main(void)
{
int m,p,e,j;
seqlist l;
Initlist(l);
printf("please input 5 word:\n");
for(int i=0;i<5;i++)
{
scanf("%d",&m);
l.elem[i]=m;
l.last++;
}
printf("please input i and e\n");
scanf("%d %d",&p,&e);
// scanf("%d",e);
Inslist(l,p,e);
}