This is a creation in Article, where the information may have evolved or changed. **1**. chain linear table from the previous example, the sequential storage structure of a linear table needs to move a large number of elements if it is necessary to insert and delete the I (1<=i<=n) elements, so we can look at another way of representing the linear table-the chain storage structure. It does not require logically adjacent elements to be physically located adjacent to each other, so the chained storage structure does not have the disadvantage of a sequential linear table, and similarly, it loses the advantage of the random storage of sequential linear tables. A linear list is characterized by the use of a set of arbitrary storage units to store data elements of a linear table (which can be contiguous or discontinuous), so in order to represent the logical relationship between data element a (i) and its direct successor, a (i+1), for data element A (i), In addition to saving the data stored by itself, you need to store a message that indicates its immediate successor (that is, a direct successor to the storage location), which is combined to form the storage image of the data element A (i), called the * * node. It consists of two domains, where the domain containing the data information stored by itself is called the data field, and the field containing the direct subsequent storage information is called * * pointer field * *. The information stored in the pointer field is called a pointer or chain. N Nodes (A (i) storage image (1<=i<=n)) are connected to a linked list. That is, the chain structure of a linear table, and because a node contains only one pointer field, it is also called a linear list or a single linked list. [Image.png] (Https://static.studygolang.com/180122/9c7239f32987cf18c82cc67ca1d33c54.png) when representing linear tables with linear lists, the logical relationship between data elements is indicated by pointers in the nodes. In other words, the pointer is an image of the logical relationship between the data elements. Logically adjacent two data elements are stored in a physical location that does not require immediate proximity, thus, this storage structure is * * Non-sequential image * * or * * Chain image * *.! [Image.png] (https://static.studygolang.com/180122/44d756591898c6208041a6896dd1b951.png) is visible by the above, the single-linked list can be specified by the head pointer, the single-linked header pointer is H, It points to the first node in the table, and if H is "empty" (l=null), the linear table represented is an "empty" table with a length of N of "0". Sometimes we have a node in front of the first node of a single linked list, called the head node. The data field of the head node can store no information, or it can store additional information such as the length of the linear table, and the pointer field of the head node stores a pointer to the first Data element (that is, where the first element node is stored). As shown:! [Image.png] (HTTps://static.studygolang.com/180122/44fdf177170abe3baccedad8ea609344.png) in the sequential storage structure of a linear table, because logically adjacent two elements are also adjacent to the physical location, So any element's storage location can be calculated from the starting position of the linear table. However, there is no fixed connection between any two element storage locations in a single-linked list. However, the storage location of each element is contained in the Information center of its direct precursor node. For example, p is a pointer to the I data element a (i) in a linear table, then P->next is a pointer to the I+1 data Element (Node A (i+1)). In other words, if p->data=a (i), then P->next->data=a (i+1). Therefore, in a single-linked list, the first Data element obtained must be looked up from the pointer. Therefore, the single-linked list is a non-random access storage structure. [Image.png] (https://static.studygolang.com/180122/d634da155175555a6ebe725bfe9e8452.png) **2**. link Table Insert Delete! [Image.png] (https://static.studygolang.com/180122/925e04c61048f430d9fc5382d6d757d8.png) To insert a data element x, first create a node with a data field of x, then insert it in a single linked list, We need to modify the pointer field of a to point to Node X. The pointer field in X should point to Node B to achieve a logical change between the 3 elements. Suppose S is a pointer to a node x, then the pointer modification above can be summed up with a statement: ' s->next=p->next;p->next = s ' or for example, after we add the data element x and want to delete it, what should we do? The answer is, we just need to modify the node A's pointer field, so that it points to B, the statement is summarized as follows: ' P->next=p->next->next ' chain linear table INSERT, delete implementation as shown below:! [Image.png] (https://static.studygolang.com/180122/f218ef7c1e71112b78095bbdc09a16e3.png)! [Image.png] (https://static.studygolang.com/180122/e8da17d41ef853e9d4a08ca6eae79720.png)! [Image.png] (httpS://static.studygolang.com/180122/a1d61b8571331eb5e429cb55a46dc13d.png) **3**. Merging of linear lists merges two ordered listings into a single sequential table, for example, We now have the head pointers for LA and LB's single-linked list, respectively, for the ordered linear table LA and LB storage structures, now combining LA and LB to get the LC. What we should do. **4**. Operation of a static linked list we can use a one-dimensional array to describe the linked list, with the following type of description:! [Image.png] (https://static.studygolang.com/180123/5e39d8d153ac69ae3a8f9b63779b0159.png)! [Image.png] (Https://static.studygolang.com/180123/e5e52d4f19b4037a30a715dc2670312b.png) This method is useful for using linked lists in high-level programming languages that do not have pointer types. A component in an array can be thought of as a node, and the 0th * * component may be considered a head node. We use cursors (that is, indicator cur) instead of pointers to indicate the relative position of the nodes in the array, as shown in the insert and delete operations. We can see that this kind of storage is pre-allocated a large amount of space, but in the insertion and deletion of the linear table, there is no need to move the element, only need to modify the pointer (where the pointer is a cursor). It still has the advantage of a chained storage structure, and in order to differentiate the linear list of pointer type representations, we call it * * static linked list * *.! [Image.png] (https://static.studygolang.com/180123/d63bdb92d5fb703a504edbf42f32b15a.png) 361 reads
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.