Home >Common Problem >A linked list is a linear list stored in what storage structure
The linked list is a linear list stored in a "chained" storage structure. The storage unit addresses occupied by the data elements of the linked list can be continuous or discontinuous. The corresponding storage space can be temporarily and dynamically allocated as needed. The logical relationship between the data elements can be expressed as a "chain" .
The operating environment of this tutorial: Windows 7 system, Dell G3 computer.
In order to overcome the shortcomings of the sequential table storage structure, make full use of storage space and improve operating efficiency, linear tables can use another storage structure - Linked storage structure. The linked storage structure of the linear list is referred to as "link list"
The storage unit addresses occupied by the data elements of the linked list can be consecutive , or it can be discontinuous, and the corresponding storage space can be temporarily and dynamically allocated as needed. The logical relationship between data elements can be expressed as a "chain".
Insertion and deletion of linked lists do not require moving data elements, only the chain needs to be modified.
Classification of linked lists:
1. Classification according to the method of linked list memory allocation
①Dynamic linked list
②Static linked list
2 .Classified by linking method
①Singly linked list
②Circular linked list
③Double linked list
(They are all dynamic linked lists)
In order to express the logical relationship between each data element ai and its direct successor data element ai 1, for each data element ai, except In addition to storing its own information, it is also necessary to store information indicating its direct successor (successor storage location-address).
The field that stores data element information is called data field, and the field that stores the immediate successor position is called pointer field, the information stored in the pointer domain is called a pointer or chain.
These two parts of information constitute the storage image of the data element ai, which is called node.
n nodes are linked into a linked list, which is the linked storage structure of a linear list (a1, a2, a3,...,an), because each node of the linked list only contains one pointer Domain, so it is called single linked list.
For linear lists, there is always a head and a tail, and linked lists are no exception. The pointer to the first node of the singly linked list in the linked list is called the head pointer. Access to the entire linked list must start from the head pointer, and each subsequent node The points are the positions pointed by the successor pointers of the previous node. The pointer of the last node of the linked list is "empty (usually represented by NULL)" - a null pointer.
In order to facilitate the implementation of various operations on the linked list, a node of the same type is set before the first data node of the singly linked list. This node is called the head node.
The data field of the head node can store a special flag information such as the length of the linked list, or it can not store any data.
The first data node and the last node of the linked list are also called head node and tail node.
Head pointer:
Head node:
/*线性表的单链表存储结构*/ /*结点定义*/ typedef struct Node { ElemType data; struct Node *next; }Node; /*单链表定义*/ typedef struct Node *LinkList;
Assume that the node storing element e is s, insert s into ai How to operate behind the node?
Thinking: Can the two inserted codes be exchanged?
No, if you switch it over, the subsequent elements such as ai 1 cannot be found, because the pointer field of s does not point to the address of ai 1.
Assume that the node storing element ai is q, and the operation of deleting node q from a singly linked list is to be implemented .
Storage method:
Time performance:
①Search
②Insertion and deletion
Space performance:
For more related knowledge, please visit FAQ column!
The above is the detailed content of A linked list is a linear list stored in what storage structure. For more information, please follow other related articles on the PHP Chinese website!