Data structure - list (a, process analysis)

First, why it is important to list

First, the list is truly dynamic data structures, and simplest kind of dynamic data organization, through the study of the list, we can more deeply understand the references and recursion can also be composed of other auxiliary data structures!

Second, what is the list

Is a list of nodes, each node comprising address data of the current node and the next node. Data stored in the node, the list is limited space, the last node when the next time is null, means that this node must be the last node. This is the list.

Advantages: dynamic arrays is true, it does not need to deal with the problem of fixed capacity. (Open space)
Cons: lose the ability to randomly access. That is not as to an array, given an index, this index it directly to the elements, it is because from the underlying mechanism, the array of open space in the memory is continuously distributed, so you can directly look for the index corresponding element, but different linked list is a direct connection layer by layer through the next, the memory location at the bottom of each node is located is different, we have a little bit to find the element we're looking for on the next.
Here Insert Picture Description

Third, the comparison of arrays and linked lists

Here Insert Picture Description

Fourth, add an element in the list header

Here Insert Picture Description

Fifth, add an element in the middle of the list

The key: find the previous node to be added
Here Insert Picture Description

Six, in order to facilitate the preparation of logic, we can adding a dummy head node.

Here Insert Picture Description

Seven, to remove the list of elements

Really correct idea Here Insert Picture Description
common mistakes
Here Insert Picture Description

Published 56 original articles · won praise 9 · views 90000 +

Guess you like

Origin blog.csdn.net/qq_43229543/article/details/103263366