#include
#define OVERFLOW 0
#define OK 1
#define MAXSIZE 1024
typedef int elemtype;
typedef struct
{
elemtype vec[MAXSIZE];
int len;
}sequenlist;
int createsqlist(sequenlist *L,int k)
{
int i;
for(i=0;i scanf("%d",&L->vec[i]);
return OK;
}
void insert(sequenlist *L, int i, int x)
{
int j;
if(L->len>=MAXSIZE)
{
printf("the list is overflow");
return NULL;
}
else if((i<1)||(i>L->len+1))
{
printf("position is not correct.\n");
return NULL;
}
else
{
for(j=L->len-1;j>=i-1;j--)
L->vec[j+1]=L->vec[j];
L->vec[i-1]=x;
L->len++;
return OK;
}
}
void del(sequenlist *L , int i)
{
int j;
if(L->len >= MAXSIZE)
{
printf("the list is overflow");
return NULL;
}
else if ( (i<1)||(i>L->len+1) )
{
printf("the position is not correct\n");
return NULL;
}
else
{
for(j=L->len-1;j>=i-1;j--)
L->vec[j-1]=L->vec[j];
L->vec[L->len-1]='\0';
L->len--;
return OK;
}
}
int main(void)
{
int i,n,x;
sequenlist *L,a;
printf("\ninput the length of the list L:\n");
scanf("%d",&n);
L=&a;
L->len=n;
createsqlist(L,n);
printf("Output the list and its length:\n");
for(i=0;ilen;i++)
printf("%d",L->vec[i]);
printf("\n this sequenlist's length is %d\n\n",L->len);
printf("input the insert location:\n");
scanf("%d",&i);
printf("input the insert data:\n");
scanf("%d",&x);
insert(L,i,x);
for(i=0;ilen;i++)
printf("%d\n",L->vec[i]);
printf("DEL function:\n input location\n");
scanf("%d",&i);
del(L,i);
printf("the length is %d\n",L->len);
for(i=0;ilen;i++)
printf("%d\n",L->vec[i]);
}
阅读(884) | 评论(0) | 转发(0) |