Static linked list
Static linked list: A linked list, described by an array, is called a cursor implementation method.
Static linked list storage structure for linear tables
#define MAXSIZE 1000
typedef struct
{
Elemtype data;//Data
int cur;//cursor
}component,staticlinklist[maxsize];
650) this.width=650; "title=" 11.jpg "src=" http://s3.51cto.com/wyfs02/M02/57/27/wKioL1STft6jGONxAADH0V1kVIU083.jpg "alt=" Wkiol1stft6jgonxaadh0v1kviu083.jpg "/>
Note that the cursor for the last element should be 0
Static linked list initialization
Status initlist (staticlinklist space)
{
int i;
for (i =0;i<maxsize-1;i++)
Space[i].cur = i+1;
space[maxsize-1].cur=0;
return OK;
}
Insert data , such as insert B in
650) this.width=650; "title=" 11.jpg "src=" http://s3.51cto.com/wyfs02/M00/57/2A/wKiom1STfa-hCmmFAAFa-SaBzE8328.jpg "alt=" Wkiom1stfa-hcmmfaafa-sabze8328.jpg "/>
First, the subscript of the idle component is obtained
int malloc_sll (staticlinklist space)
{
int i = space[0].cur;
if (space[0].cur)//If it is an empty list
Space[0].cur = space[i].cur;//as a component spare
return i;
}
Sample code
Status Listinsert (staticlinklist l,int i,elemtype e)
{
int j,k,l;
K = max_size-1;
if (i<1 | | i>listlength (L) +1)
{
return ERROR;
}
j = malloc_sll (L);//Call the function written above,
if (j)
{
L[j].data = e;
for (l=1;l<=i-1;l++)
{
K = L[k].cur;
}
L[j].cur = L[k].cur;
L[k].cur = j;
return OK;
}
return ERROR;
}
Delete operation
650) this.width=650; "title=" 11.jpg "src=" http://s3.51cto.com/wyfs02/M02/57/28/wKioL1STg1TTn7fqAAHvw03C2fQ503.jpg "alt=" Wkiol1stg1ttn7fqaahvw03c2fq503.jpg "/>
Sample code
Status Listinsert (staticlinklist l,int i)
{
int j,k;
K = max_size-1;
if (i<1 | | i>listlength (L))
{
return ERROR;
}
j = malloc_sll (L);//Call the function written above,
for (j=1;j<=i-1;j++)
{
K = L[k].cur;
}
j = l[k].cur;
L[k].cur = L[j].cur;
return OK;
}
Data structures and algorithms-Learning note 7