Linear tables are divided into sequential tables and linked lists.
The basic operations of the sequential table are as follows:
#include <stdio.h> #include <stdlib.h>/*---------------------------------------------*/#define Init_ Volume_of_list 100#define increse_volume 10/*---------------------------------------------*/typedef char elemtype; typedef struct{ELEMTYPE* Elem; int icurrentvolume; int icurrentlength; int Iincresevolume;} sqlist;/*---------------------------------------------*/void errormsg (char *s); void testsq (SqList L); void Sqlistinit (sqlist* L); int Sqlocateelem (SqList l,elemtype e); void Sqinsertelem (sqlist* l,int i,elemtype e);/*---------- -----------------------------------*/void errormsg (char *s) {printf ("%s", s);} /*---------------------------------------------*/void testsq (sqlist L) {int i=0; printf ("%d%d%d%d \ n", L.elem,l.icurrentlength,l.icurrentvolume,l.iincresevolume); if (l.icurrentlength! = 0) while (i<=l.icurrentlength-1) printf ("l.elem[%d] = '%c ' \ n", i-1,l.elem[i++]); }/*---------------------------------------------*/void Sqlistinit (sqlist* L) {L->elem = (elemtype*) malloc (sizeof (elemtype) *l->icurrentvolume); if (! ( L->elem)) {errormsg ("Malloc failed!"); Exit (1); } l->icurrentlength = 0; L->icurrentvolume = init_volume_of_list; L->iincresevolume = Increse_volume;} /*---------------------------------------------*/void sqinputinitdata (sqlist* l,int N) {elemtype c= ' a '; int i = 1; if (n>l->icurrentvolume) {errormsg ("Out of Volume,please expand volume!"); Exit (1); } while (n--) {Sqinsertelem (l,i,c); i++; c + = 1; }}/*---------------------------------------------*/int Sqlocateelem (sqlist l,elemtype e) {int isequencenum=0; elemtype* p = NULL; p = L.elem; while (Isequencenum<=l.icurrentlength && *p!=e) {isequencenum++; p++; } if (isequencenum<=l.icurrentlength) return isequencenum; return 0;} /*---------------------------------------------*/void SqinsertelEM (sqlist* l,int i,elemtype e) {//insert e before I elemtype* p=null; Elemtype* Q=null; if (i<1 | | i>l->icurrentlength+1) {errormsg ("I am out of range!"); Exit (1); } p = & (L->elem[i-1]); For (q=p;q>& (l->elem[l->icurrentlength-1]); q--) * (p+1) = *p; *p = e; l->icurrentlength++;} /*---------------------------------------------*/int Main () {sqlist La; Sqlistinit (&la); Sqinputinitdata (&la,26); TESTSQ (La); return 0;} /*---------------------------------------------*/
void ErrorMsg (char *s);/* ERROR output function */
void Testsq (SqList L);/* Simple test for successful initialization of linear tables */
void Sqlistinit (sqlist* L);/* Initialize linear table as empty table */
int Sqlocateelem (sqlist l,elemtype e);/* Position Order TABLE element */
void Sqinsertelem (sqlist* l,int i,elemtype e);/* Insert an element before I */
void Sqinputinitdata (sqlist* l,int n);/* Initialize linear table data */
[BS] Linear table-sequential table basic operations