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.
Third, the comparison of arrays and linked lists
Fourth, add an element in the list header
Fifth, add an element in the middle of the list
The key: find the previous node to be added
Six, in order to facilitate the preparation of logic, we can adding a dummy head node.
Seven, to remove the list of elements
Really correct idea
common mistakes