This article references:
1, "Big liar data Structure"
2, http://blog.csdn.net/jzhf2012/article/details/8540543
3, http://blog.csdn.net/jzhf2012/article/details/8540410
4, http://www.cnblogs.com/ITtangtang/p/3948610.html
5, http://blog.csdn.net/zw0283/article/details/51132161
Originally in the analysis after HashSet, HashMap, I want to follow the analysis TreeMap and TreeSet, but when I read the source, I gave up the idea. is not the source of how difficult, but treemap involved in the data structure of the tree structure, and I have been analyzing the linear structure, and ArrayList, LinkedList is a linear structure, and has not been analyzed. Therefore, I decided to proceed in a step-by-step manner by first analyzing all the linear tables and then analyzing the treemap.
ArrayList The basic logic structure of the underlying source code is simple, in the "JDK learning---in-depth understanding of string in Java" article has been basically analyzed, the only difference is that the underlying array of string is immutable, In ArrayList's bottom object[] array, allowing the array to increment, delete, and support the dynamic expansion of the array , these things are not difficult, I believe the reader can easily understand this knowledge, I will no longer explain.
This article I will focus on the LinkedList knowledge points, and the bottom of LinkedList is a doubly linked list structure, so I will parse the source code, interspersed with some of the two-way linked list of knowledge, and then combined with code analysis. I don't like very empty alone to say the data structure, one is because I level limited said not clear, two is because I think the theory needs to combine code, so analysis more intuitive. If the reader wants to know more about the data structure, you can find some books to read.
Doubly linked list
"JDK Learning---in-depth understanding of string in Java" describes the general architecture of the data structure, "JDK learning---in-depth understanding of Java HashMap, HashSet Bottom implementation" describes the linear table of a single-linked list.
This article will continue to introduce a doubly linked list of data structures.
Doubly linked list: In each node of a single linked list, set a pointer field "DP" to its front predecessor node
Since it is a doubly linked list, then for one node in the list (p), the successor of its predecessor, and the predecessor, is actually the node itself:
P->next->prior = p = P->next-prior
The insertion of a doubly linked list is not complicated, but the order is important and must never be written wrong.
Suppose we now have a node s, which stores an element of E, now to insert the node S into the node p and P->next, it is necessary to strictly abide by the order of insertion, such as:
S--prior = p; Assign p to the precursor of S, 1s, next = p-Next; Assign P--next to the successor of S, 2p, next, prior = s; Assign S to P->next's precursor, 3p to next =s; Assigning S to the successor of P, 4
The key is their order, because the 2nd, 3 steps are used P->next, if the 4th step first, it will make p->next advance into s, so that the insertion work can not be completed. The formula is: First to take the precursor of S and successor, and then fix the successor, and finally solve the successor of the former node.
If the insert operation is understood, then the delete operation is simple.
P->prior next = P-Next; P->next assigned to the successor of P->prior, 1p->next-prior = P->prior; p->prior was assigned to the precursor of P->next, medium 2free (p); Release Node P
Summary: Doubly linked list for a single-linked list, add, delete operations to be more complex, after all, a prior pointer field, so the operation requires extra care. In addition, since each node needs to record two pointers, the space is relatively occupied a little more. However, due to its good symmetry, it makes it convenient to increase and delete a node. To put it bluntly, is to use space for time.
JDK Learning---in-depth understanding of LinkedList in Java