各高手帮忙看一下这道插入函数为什么弄不出来!
#include<stdio.h>#include<malloc.h>
#define MAXNUM 20
struct listtype
{
int data[MAXNUM];
int length;
};
void insert(struct listtype *l,int i,int x)
{
int j;
for(j=l->length-1;j>=i;j--)
l->data[j+1]=l->data[j];
l->data[i-1]=x;
l->length++;
for(j=0;j<(l->length);j++)
printf("%d,",l->data[j]);
}
void main()
{
int i,x,j;
struct listtype *lp;
lp=(struct listtype *)malloc(sizeof(struct listtype));
lp->length=0;
for(j=0;lp->data[j]!=-1;j++)
scanf("%d",&lp->data[j]);
lp->length=j;
/* for(i=0;i<j;i++)
printf("%d,",lp->data[i]);*/
printf("\n");
scanf("%d,%d",&i,&x);
insert(lp,i,x);
}