我想对顺序表进行插入和删除 , 没有错误 可以运行 , 可是结果怎么是错误的啊 ,大家帮我看看
#define listsize 100
#include <stdio.h>
#include <malloc.h>
struct seqlist{
int data[listsize];
int length;
};
int i;
void insertlist(struct seqlist *l,int x,int i)
{
int j ;
if(i<0||i>l->length)
printf("error");
if(l->length>=listsize)
printf("error");
for(j=l->length-1;j>=i;j--)
l->data[j+1]=l->data[j];
l->data[i]=x;
}
void initlist(struct seqlist *l)
{
l->length=0;
}
void displaylist(struct seqlist *l)
{
int i;
puts("now the list is:");
for(i=0;i<l->length;i++)
printf("%d",l->data[i]);
printf("\n");
return;
}
void main()
{
struct seqlist *q;
int i,n,t;
q=(struct seqlist *)malloc(sizeof(struct seqlist));
initlist(q);
puts("pleast input the size of the list:");
scanf("%d",&n);
printf("please input the elements of the list one by one:");
for(i=0;i<n;i++)
{
scanf("%d",&t);
insertlist(q,t,i);
}
displaylist(q);
puts("please input the position of the element:");
scanf("%d",&i);
insertlist(q,t,i);
displaylist(q);
puts("\n press any key to quit ...");
}