Figure 1 is the logical state of a linear table (ZHAO, QIAN, SUN, LI, ZHOU, WU, ZHENG, WANG). The head pointer indicates where the first node in the list (that is, the storage image of the first Data element) is stored. At the same time, because the last data element has no direct successor, the pointer to the last node in the linear list is "empty" (null).
Figure 1 Logical state of a linear list
As the above description shows, a single-linked list can be uniquely determined by a header pointer, and is described in the C language using the "struct pointer".
[CPP]View Plaincopy
- Single-linked table storage structure-----Linear table-----
- typedefstruct LNODE{  
- elemtype data ;
- struct LNODE  *NEXT;  
- }lnode, *linklist;
Sometimes a node is attached before the first node of a single linked list, which is called the head node . The data field of the head node can store no information or store additional information such as linear table lengths, and the pointer field of the head node stores the pointer to the first node (that is, where the first element node is stored). 2 (a), at this point, the head pointer of the single-linked list points to the head node. If the linear table is empty, the pointer field of the head node is "empty", as shown in 2 (b).
Figure 2 Single-linked list (a) Non-empty table with lead node; (b) Empty table
A circular linked list is another form of chained storage structure. Its characteristic is that the pointer field of the last node in the table points to the head node, and the entire list forms a ring. As a result, other nodes in the table can be found from any of the nodes in the table, and 3 is a single-chain circular list.
Figure 3 Single-chain cycle table (a) Non-empty table; (b) Empty table
The operation of the circular list is basically consistent with the linear list, except that the loop condition in the algorithm is not whether p or P->next is empty, but whether they are equal to the head pointer, but sometimes, if a tail pointer is set in the loop linked list without a head pointer (4 (a)), some operations can be simplified. For example, when you combine two linear tables into one table, you only need to connect the end table of one table to the Header table of another table. This operation only needs to change two pointer values when the linear table is used as the storage structure of the circular linked list of Figure 2.4 (a), and the operating time is O (1). As shown in table 4 (b) after merging.
Figure 4 Circular chain list (a) with only tail pointers (a) two linked lists; (b) Consolidated table
only one of the nodes in the chained storage structure discussed above indicates a direct successor to the Pointer field, from which a node can only follow the pointer back tracing other nodes. To tracing the direct forward of a node, you need to start from the table header pointer. In other words, in a single-linked list, the execution time of Nextelem is O (1), while the execution time of Priorelem is O (n). In order to overcome the disadvantage of one-way single-linked list, we can use the doubly linked list . As the name implies, there are two pointer fields in the nodes of the doubly linked list, one pointing directly to the successor and the other pointing directly to the preceding trend. The following can be described in the C language:
[CPP]View Plaincopy
- //-----Linear Table of two-way linked list storage structure-----  
- typedefstruct DULNODE{  
- elemtype data ;
- struct DULNODE  *PRIOR;  
- struct DULNODE  *NEXT;  
- }dulnode, *dulinklist;
Like a single-strand loop table, a doubly linked list can also have a loop table, 5 (c), a list of two rings, and Figure 5 (b) shows an empty table with only one header node. In a doubly linked list, if D is a pointer to one of the nodes in the table (that is, D is a dulinklist variable), there is obviously
D->next->prior=d->prior->next=d
Figure 5 Two-way chain example (a) node structure; (b) An empty two-way circular link list; (c) A non-empty bidirectional circular link list
Head Knot Point