#include<stdio.h>
#include<alloc.h>
#define MAXSIZE 20
#define datatype char
typedef struct
{ datatype data[MAXSIZE];
int last;
}SeqList;
SeqList *init_SeqList()
{ SeqList *L;
L=(SeqList*)malloc(sizeof(SeqList));
L->last=-1; return L;}
int Insert_SeqList(SeqList *L,int i,datatype x)
{int j;
if (L->last==MAXSIZE-1)
{ printf("full"); return(-1); }
if (i<1 || i>L->last+2)
{ printf("error place");return(0); }
for(j=L->last;j>=i-1;j--)
L->data[j+1]=L->data[j];
L->data[i-1]=x;
L->last++;
return (1);
}
int Delete_SeqList(SeqList *L,int i)
{ int j; /*检查空表及删除位置的合法性 */
if(i<1 || i>L->last+1)
{ printf ("i is out of place"); return(0); }
for(j=i;j<=L->last;j++)
L->data[j-1]=L->data[j]; /*向上移动 */
L->last--;
return(1); /*删除成功 */
}
void main()
{ int n,i=0;char ch;
SeqList *L;
L=init_SeqList();
while((ch=getchar())!='\n')
{ L->data[i]=ch; i++;
L->last++;}
for(i=0;i<L->last+1;i++)
printf("%c",L->data[i]);
Insert_SeqList(L,3,‘*’); printf(“插入后输出” );
for(i=0;i<L->last+1;i++)
printf("%c\n",L->data[i]);
Delete_SeqList(L,4); printf(“删除后输出” );
for(i=0;i<L->last+1;i++)
printf("%c\n",L->data[i]);}
#include<alloc.h>
#define MAXSIZE 20
#define datatype char
typedef struct
{ datatype data[MAXSIZE];
int last;
}SeqList;
SeqList *init_SeqList()
{ SeqList *L;
L=(SeqList*)malloc(sizeof(SeqList));
L->last=-1; return L;}
int Insert_SeqList(SeqList *L,int i,datatype x)
{int j;
if (L->last==MAXSIZE-1)
{ printf("full"); return(-1); }
if (i<1 || i>L->last+2)
{ printf("error place");return(0); }
for(j=L->last;j>=i-1;j--)
L->data[j+1]=L->data[j];
L->data[i-1]=x;
L->last++;
return (1);
}
int Delete_SeqList(SeqList *L,int i)
{ int j; /*检查空表及删除位置的合法性 */
if(i<1 || i>L->last+1)
{ printf ("i is out of place"); return(0); }
for(j=i;j<=L->last;j++)
L->data[j-1]=L->data[j]; /*向上移动 */
L->last--;
return(1); /*删除成功 */
}
void main()
{ int n,i=0;char ch;
SeqList *L;
L=init_SeqList();
while((ch=getchar())!='\n')
{ L->data[i]=ch; i++;
L->last++;}
for(i=0;i<L->last+1;i++)
printf("%c",L->data[i]);
Insert_SeqList(L,3,‘*’); printf(“插入后输出” );
for(i=0;i<L->last+1;i++)
printf("%c\n",L->data[i]);
Delete_SeqList(L,4); printf(“删除后输出” );
for(i=0;i<L->last+1;i++)
printf("%c\n",L->data[i]);}