#include int Delete Seqlist(seq list *L, int i) #include ntj;/*检查空表及删除位置的合法性* #define maXsize 20 f(iL->last1) #define datatype char i printf ("i is out of place"); return(0);) typedef struct forGi;jlast:j++ i datatype data MAXSIZe L→>data[j-1]-L-→datl;/*向上移动* nt last L->last iSeqlist; return(1),/*删除成功* Seqlist *init Seqlisto i Seqlist * L void maino L=(SeqList)malloc(sizeof( Seq List));i int n, i=0; char ch; L->last=-1; return L; I q int Insert Seqlist(seq list *L, int i, datatype x) L=init Seq listO fint j while((ch=getchar)=n) if ( L->last=MAXSIZE-1 i L->datal]=ch; i++ i printf("full"; return(-1);) L->last++;) if(ilast+2) for(i=0; Klast+1; 1++) i printf("error place"), return(0); printf("%oc"L->data[i ); for(L->last; ]>=1-1; j--) Insert Seqlist(L,3,*), printf(“插入后输 L->data[j+1]F=L->data[jI 出”) for(i=0 Klast+1; 1++) L->last++ printf("%ocn" L->datai return (1) Delete SeqList(L,4); printf((“删除后输出”); fori=0; ilast+1; 1++) talil: t
#include #include #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 (iL->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(iL->last+1) { printf ("i is out of place"); return(0); } for(j=i;jlast;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;ilast+1;i++) printf("%c",L->data[i]); Insert_SeqList(L,3,‘*’); printf(“插入后输 出”); for(i=0;ilast+1;i++) printf("%c\n",L->data[i]); Delete_SeqList(L,4); printf(“删除后输出”); for(i=0;ilast+1;i++) printf("%c\n",L->data[i]);}