A linear table is a finite sequence of n data elements, characterized by a linear relationship between data elements. The two different storage structures that represent this relationship in a computer are sequential storage structures and chained storage structures.
1. Sequential table
A sequential table is an array of data elements that store linear tables sequentially in memory using a contiguous set of storage units. The logical relationship of a data element in a sequential table is represented by its "storage location adjacent".
For the sequential table, there are basic operations such as initialization, building, destroying, inserting, deleting, searching by value, etc. The insert and delete operations require about half of the elements to be moved, and the time complexity is O (n).
2. Linked list
In addition to the commonly used single-linked list, there are circular linked lists, two-way linked lists, two-way circular linked lists, static linked lists and other forms, single-linked list is the focus of the list.
(1) Single linked list
A chained storage structure stores data elements in a linear table with an arbitrary set of storage units of addresses. The single-linked list is one of the simplest chain storage structures, which can be described by the "pointer structure" in C language.
To unify operations when inserting or deleting nodes at any location, a node is attached to the first node (first node) of a common 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 linked list, and the pointer field of the head node stores pointers to the first node.
For single-linked lists, there are mainly initialization, table length, search by ordinal, search by value, insert, delete, establish and so on. The insertion and deletion only need to modify the pointer, without moving the data, its time complexity is O (n), the single-linked list has two methods of head interpolation and tail interpolation method.
(2) Single cycle linked list
On the basis of a single linked list, the pointer field of the last node points to the single-loop linked list of the nodes. The only difference between a single-loop and a single-linked list is that the criteria for judging the last node in the list is no longer "successor is null", but "successor is the head node". The single-loop linked list operation is almost identical to that of a single-linked list, except that the pointer to the last node points to the head node. Single-loop linked lists tend to have only tail pointers.
(3) Doubly linked list
The doubly linked list adds a pointer field to the precursor compared to a single linked list. The various operation implementations of the doubly linked list can be modeled as a single-linked list response operation, only to note that two pointers need to be modified. A double chain list L can be seen as two opposite individual lists, one is the single list of the leading nodes (L points to the head node), one is not the lead node (l points to the end of the node), so it is different to delete the tail node in the doubly linked table and delete the nodes in other locations. At the end of the insertion node and in other locations of the operation is also different, which only need to consider from two single-linked list can be well understood. It is also important to note the similarities and differences between the two-way linked list and the single-linked list.
(4) Bidirectional circular link list
The two-way circular linked list, compared with the doubly linked list, only points the precursor pointer field of the head node to the last one, so the operation of the bidirectional circular list is similar to the doubly linked list. A two-way circular linked list can be seen as a two-directional single-loop linked list.
(5) Static linked list
A static linked list is used to represent and implement a linked list, and its related operations are similar to a single linked list.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Related basic concepts of linear tables