# include & lt; String. H>
#include
#include
#include
#include
#include
#include
#include
#include
#include
# define TRUE 1
# define FALSE 0
# define OK 1
# define the ERROR 0
Typedef int the Status;
Typedef int Boolean;
Typedef int ElemTtpe;
//typedef ElemType * Triplet;
/c2-3 h static singly linked list storage structure of linear table,
# define MAX_SIZE 100
Typedef struct
{
ElemType data;
Int cur;
} component, SLinkList [MAX_SIZE];
/bo2-5. H static linked list (defined data structure by c2-3 h) of the basic operations (13)
# define DestroyList ClearList//DestroyList () and ClearList () is the same as
Int Malloc (SLinkList space)
{//standby list is not empty, it returns the allocation of node index (the first node of the standby list); Otherwise returns 0
Int I=space [0]. Cur;//standby list the position of the first node
If (I)
Space [0]. Cur=space [I]. Cur;
return i;
}
Void Free (SLinkList space, int k)
{
//subscript k as recycling idle nodes to the standby list (as standby list of the first node)
Space [k]. Cur=space [0]. Cur;
Space [0]. Cur=k;
}
Void InitList (SLinkList L)
{
//constructs an empty list L, header for the last unit of L L [MAX_SIZE - 1], the rest of the unit chain into
//a spare list, header for the first unit of L L [0], "0" said null Pointers,
int i;
L [MAX_SIZE - 1]. The cur=0;
for(i=0; iL [I]. Cur=I + 1;
L [MAX_SIZE - 2). The cur=0;
}
Void ClearList (SLinkList L)
{
//initial conditions: linear table already exists, results: the operation will be reset to the empty table L
Int j, I=[0] L. Cur;
While (I)
{
J=I;
I=L [I]. Cur;
}
L [j]. Journal of cur=L [MAX_SIZE - 1]. Cur.
L [MAX_SIZE - 1]. The cur=0;
}
The Status ListEmpty SLinkList (L)
{
//if L is empty table, then return TRUE; Otherwise it returns FALSE
If (L [MAX_SIZE - 1]. Cur==0)
Return TRUE;
The else
Return FALSE;
}
Int ListLength SLinkList (L)
{
//return the number of data elements in L
Int j=0, I=L [MAX_SIZE - 1]. Cur.
While (I)
{
I=L [I]. Cur;
j++;
}
Return j;
}
Status GetElem (SLinkList L, int I ElemType & amp; E)
{
With e//returns the value of the ith a elements in L
Int j, k=MAX_SIZE - 1;
If (i<1 | | i> ListLength (L))
return ERROR;
For (m=1; M<=I; M++)
K=L [k]. Cur;
E=L [k]. Data;
return OK;
}
Int LocateElem (SLinkList L, ElemType e)
{
//in static single linear table L find the first value for e element, if found, it returns it in L in order; Otherwise returns 0
//(with other LocateElem () the definition of different)
Int I=L [MAX_SIZE - 1]. Cur.
While (I & amp; & L [I]. The data!=e)
I=L [I]. Cur;
return i;
}
The Status PriorElem (SLinkList L, ElemType cur_e, ElemType & amp; Pre_e)
{
//initial conditions: linear table L there
//operating results: if cur_e is L data elements, and it was not the first, use pre_e returns its precursor;
//otherwise fails, pre_e no definition
Int j, I=L [MAX_SIZE - 1]. Cur;
Do
{
J=I;
I=L [I]. Cur;
} while (I & amp; & Cur_e! [I]=L data);
If (I)
{
Pre_e=L [j]. Journal of data;
return OK;
}
return ERROR;
}
The Status NextElem (SLinkList L, ElemType cur_e, ElemType & amp; Next_e)
{
//initial conditions: linear table L existing
//operating results: if cur_e is data L data elements, and not the final one, use next_e returns its successor;
//otherwise fails, next_e no definition
Int j, I=LocateElem (L, cur_e);
If (I)
{
J=L [I] cur;
If (j)
{
Next_e=L [j]. Journal of data;
return OK;
}
}
return ERROR;
}
The Status ListInsert (int I SLinkList L, ElemType e)
{
//before the first I elements in L insert a new data element e
Int j, j, k=MAX_SIZE - 1;
If ((i<1 | | i> ListLength (L) + 1))
return ERROR;
J=Malloc (L);
If (j)
{
L [j] data=https://bbs.csdn.net/topics/e;
For (m=1; MK=L [k]. Cur;
L [j]. Journal of cur=L [k]. Cur.
L [k]. Cur=j;
return OK;
}
Return the ERROR;
}
Status ListDelete (SLinkList L, int I ElemType & amp; E)
{
//delete in the l number in the ith element e, and returns its value
Int j, k=MAX_SIZE - 1;
If (i<1 | | i> ListLength (L))
return ERROR;
for(j=1; jK=L [k]. Cur;
J=L [k]. Cur;
L [k]. Cur=L [j]. Cur.
E=L [j]. Journal of data;
Free (L, j);
return OK;
}
Void ListTraverse (SLinkList L, void * visit (ElemType))
{
//initial conditions: linear table L exist, results: the operation, in turn, each data element of L function call visit ()
Int I=L [MAX_SIZE - 1]. Cur.
While (I)
{
Visit (L [I]. Data);
I=L [I]. Cur;
}
printf("\n");
}
The Status equal (ElemType ElemType c1, c2)
{
//determine whether equal function
If (c1==c2)
Return TRUE;
The else
Return FALSE;
}
Int comp (ElemType a, ElemType b)
{
//according to aIf (a==b)
return 0;
The else
Return (a - b)/abs (a - b);
}
Void print (ElemType c)
{
Printf (" % d ", c);
}
Void print1 (ElemType & amp; C)
{
//in the form of a decimal integer value of the output element
Printf (" % d ", c);
}
Void print2 (ElemType c)
{
//in the form of character value of the output element
Printf (" % c ", c);
}
//func2-3 h inspection singly linked lists basic operation of the main function
//main2-2. CPP, main2-3. CPP. Main2-4. CPP and main2-5. CPP call
Int main (void)
{
LinkList L;
ElemType e, e0.
The Status of I;
Int j, k;
InitList(L);
for(j=1; j<=5; J++)
I=ListInsert (L, 1, j);
Printf (" in the header of L insert in turn after 1 to 5, L=");
ListTraverse (L, print);
I=ListEmpty (L);
Printf (" L is free? nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull