#include <stdio.h>#defineMaxSize 100typedefintDatatype;typedefstruct//define structure Body seqlist{DataType list[maxsize]; intsize;} Seqlist;//Initialization Order table LvoidListinitiate (Seqlist *L) {L->size=0;//define the number of initial data elements}intListlength (Seqlist L)//current number of data elements{ returnl.size;}intListinsert (Seqlist *l,intI,datatype x) { intJ; if(l->size>=MaxSize) {printf ("Order table is full cannot insert!\n"); return 0; } Else if(i<0|| I>l->size) {printf ("i is error"); return 0; } Else { for(j=l->size; j>i-1; j--) l->list[j]=l->list[j-1]; L->list[i-1]=x; L->size++; return 0; }}//Deleting data elementsintListdelete (Seqlist *l,inti) { intJ; if(l->size<=0) {printf ("The sequential table has no data elements to delete!\n"); return 0; } Else if(i<0|| i>l->size-1) {printf ("i is error\n"); return 0; } Else { //*x=l->list[i]; for(J=i; j<=l->size-1; J + +) l->list[j-1]=l->List[j]; L->size--; return 0; }}intMainvoid) {seqlist la,lb,lc; inti,x; intN,m;//Linear table LengthListinitiate (&La); printf ("Please enter the length of the linear table LA:"); scanf ("%d",&N); La.size=N; printf ("Please enter the elements in the linear table LA:"); for(i=0; i<n; i++) scanf ("%d",&La.list[i]); printf ("Please enter the number x to insert into the linear table LA and the position i insert:"); scanf ("%d%d",&x,&i); Listinsert (&la,i,x); printf ("Linear table La="); for(i=0; i<la.size; i++) printf ("%d", La.list[i]); printf ("\ n Enter the location of the number you want to delete:"); scanf ("%d",&i); Listdelete (&la,i); printf ("Linear table La="); for(i=0; i<la.size; i++) printf ("%d", La.list[i]); return 0;}
Implement initialization, insertion, deletion, and display of linear tables using sequential storage structure definition (static) of linear tables