LinkedList features non-thread-safe support for serializing doubly linked list member variables
transient int size = 0;
Transient node<e> first; Point to first element
Transient node<e> last; Point to last Element
Linked list nodes, three attributes: element, previous node, next node
Private Static class Node<e> { E item; Node<E> next; Node<E> prev; Node (node<E> prev, E element, node<e> next) { this. Item= element; this. Next = next; this. prev = prev; }}
Basic method Add
Public BooleanAdd (e e) {linklast (e); return true;}voidLinklast (e e) {FinalNode<e> lasttmp =Last ; FinalNode<e> NewNode =NewNode<> (Lasttmp, E,NULL); Last=NewNode; if(Lasttmp = =NULL) First=NewNode; ElseLasttmp.next=NewNode; Size++; Modcount++;}
Delete Remove
PublicE Removelast () {Finalnode<e> L =Last ; if(L = =NULL) Throw Newnosuchelementexception (); returnUnlinklast (l);}PrivateE Unlinklast (node<e>l) {//assert L = = Last && L! = null; FinalE element =L.item; FinalNode<e> prev =L.prev; L.item=NULL; L.prev=NULL;//Help GCLast =prev; if(prev = =NULL) First=NULL; ElsePrev.next=NULL; Size--; Modcount++; returnelement;}
The principle of changing the Set check get expansion
Add new nodes backwards
Some questions reference
http://blog.csdn.net/ns_code/article/details/35787253
Java Collection Class-linkedlist analysis