Data structure notes - linear table (below)

After understanding the linked storage structure of linear lists, someone came up with the idea of ​​using arrays instead of pointers to describe singly linked lists. See how they do it.

static linked list

Let the elements of the array consist of two data fields, data and cur. That is, each subscript of the array has a corresponding data and cur. The data field data is used to store data elements, and cur is equivalent to the next pointer in the singly linked list, which stores the subscript of the element's successor in the array. We call cur the cursor.

This linked list described by an array is called a static linked list , and we call this description a cursor implementation.

In addition, we treat the first and last elements of the array as special elements, and no data is stored. We usually refer to unused array elements as alternate lists .

The first element of the array, that is, the cur of the element with the subscript 0, stores the subscript of the first node of the alternate linked list; and the cur of the last element of the array stores the subscript of the first element with a value, which is equivalent to a singly linked list. The role of the head node in .

As shown below:
write picture description here

We have a simple understanding of the insertion and deletion of static linked lists as follows:

The problem to be solved in the static linked list is: how to use static simulation to allocate the storage space of the dynamic linked list, apply for it when needed, and release it when it is useless.

Insertion of static linked list

write picture description here

Deletion of static linked list

write picture description here

Advantages and disadvantages of static linked list

  • During insertion and deletion operations, only the cursor needs to be modified, and elements do not need to be moved, thereby improving the disadvantage that insertion and deletion operations in the sequential storage structure need to move a large number of elements.
  • It does not solve the problem that the table length caused by continuous memory allocation is difficult to determine.
  • The random access characteristic of sequential storage structure is lost.

Circular linked list

For a singly linked list, since each node only stores the backward pointer, the backward chain operation is stopped when the tail is reached, so that when a node cannot find its predecessor node.

The pointer end of the terminal node in the singly linked list is changed from a null pointer to point to the head node, so that the entire singly linked list forms a ring .

Obviously solves a problem: when starting from a node, visit all nodes of the linked list.
write picture description here

Doubly linked list

Doubly linked list: In each node of the singly linked list, a pointer field pointing to its predecessor node is set .

The advantage of a doubly linked list: a node operates faster on the previous and subsequent nodes;

Disadvantages of doubly linked list: one node, two pointers, more memory consumption.

Since a singly linked list can be a circular linked list, of course, a doubly linked list can also be a circular list, and its structure is as follows:

write picture description here

Doubly linked list insertion

delete doubly linked list

write picture description here

The linear table is sorted here. If there are any mistakes or deficiencies in the text, I hope everyone can give me feedback and make progress together.

For more exciting content, pay attention to my WeChat public account - Android motor vehicle
write picture description here

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325441446&siteId=291194637