The simplest part of a data structure based on a list of sequential lists is actually a struct array code which is relatively simple as follows
1#include"stdio.h"2#include"string.h"3 #defineMAXSIZE 1004 5 6 7typedefstruct8 {9 Charkey[ the];Ten Charname[ -]; One intAge ; A }data; - - thetypedefstruct - { -DATA listdata[maxsize+1]; - intListlen; + }seqlisttype; - + A at voidSeqlistinit (Seqlisttype *SL);//Initialization Order Table - intSeqlistlength (Seqlisttype *SL);//returns the number of elements in a sequential table - intSeqlistadd (Seqlisttype *sl,data DATA);//adding elements to the sequential table - intSeqlistinsert (Seqlisttype *SL,intN,data DATA);//inserting elements into the sequential table - intSeqlistdelete (Seqlisttype *SL,intn);//Delete data elements in a sequential table -DATA *seqlistfindbynum (Seqlisttype *sl,intn);//returns an element based on an ordinal in intSeqlistfindbycont (Seqlisttype *SL,Char*key);//Find by keyword - intSeqlistall (Seqlisttype *SL);//traversing the contents of a sequential table to + - intMain () the { * inti; $ Seqlisttype SL;Panax NotoginsengDATA data,*data1; - CharKey [ the]; the +Seqlistinit (&SL); A Do the { +printf"Enter the added node: Learn the name Age:"); - fflush (stdin); $scanf"%s%s%d",&data.key,&data.name,&data.age); $ if(data.age) - { - if(! Seqlistadd (&sl,data))//If the Add node fails the Break; - } Wuyi Else the Break; -} while(1); Wuprintf"the order of nodes in the \ n sequential table is: \ n"); -Seqlistall (&SL); About $ fflush (stdin); -printf"\ n The number of the node to be removed:"); -scanf"%d",&i); -Data1=seqlistfindbynum (&sl,i); A if(data1) +printf"the first%d nodes are:%s,%s,%d\n",i,data1->key,data1->name,data1->Age ); the - fflush (stdin); $printf"\ n to find the keyword for the byte:"); thescanf"%s", key); theI=seqlistfindbycont (&sl,key); theData1=seqlistfindbynum (&sl,i); the if(data1) -printf"the first%d nodes are:%s,%s,%d\n",i,data1->key,data1->name,data1->Age ); in the return 0; the } About the the voidSeqlistinit (Seqlisttype *SL) the { +sl->listlen=0;//when initializing, set the order table length to 0 - } the Bayi intSeqlistlength (Seqlisttype *SL) the { the return(sl->Listlen); - } - the intSeqlistadd (Seqlisttype *sl,data DATA) the { the if(sl->listlen==MAXSIZE) the { -printf"The order table is full and no more nodes can be added"); the return 0; the } thesl->listdata[++sl->listlen]=data;94 return 1; the } the the intSeqlistinsert (Seqlisttype *SL,intn,data DATA)98 { About inti; - if(sl->listlen>MAXSIZE)101 {102printf"Order table is full, cannot insert node");103 return 0; 104 } the if(n<1|| N>sl->Listlen)106 {107printf"Insert node ordinal error, cannot insert element");108 return 0; 109 } the for(i=sl->listlen;i>=n;i--)111sl->listdata[i+1]=sl->Listdata[i]; thesl->listdata[n]=data;113sl->listlen++; the return 1; the } the intSeqlistdelete (Seqlisttype *SL,intN)117 {118 inti;119 if(n<1|| N>sl->Listlen) - {121printf"Delete node ordinal error, cannot delete element");122 return 0; 123 }124 for(i=n;i<sl->listlen;i++) thesl->listdata[i]=sl->listdata[i+1];126sl->listlen--;127 return 1; - }129DATA *seqlistfindbynum (Seqlisttype *sl,intN) the {131 if(n<1|| N>sl->Listlen) the {133printf"node ordinal error, cannot return node");134 return 0; 135 }136 return& (sl->listdata[n]);137 }138 139 intSeqlistfindbycont (Seqlisttype *SL,Char*key) $ {141 inti;142 for(i=1; i<=sl->listlen;i++)143 if(strcmp (sl->listdata[i].key,key) = =0)144 returni;145 return 0;146 }147 intSeqlistall (Seqlisttype *SL)148 {149 inti; Max for(i=1; i<=sl->listlen;i++)151printf"%s,%s,%d\n",sl->listdata[i].key,sl->listdata[i].name,sl->listdata[i].age); the}
Sequential Linked list notes