What is 1.LinkedList? What are the characteristics
LinkedList is an ordered sequence that can be efficiently inserted and removed at any location, based on a doubly linked list.
LinkedList is a doubly linked list that inherits from Abstractsequentiallist. It can also be manipulated as a stack, queue, or double-ended queue.
The LinkedList implements the List interface and can queue operations on it.
LinkedList implements the Deque interface, which means that linkedlist can be used as a double-ended queue.
LinkedList implements the Cloneable interface, which covers the function clone () and can be cloned.
The LinkedList implements the Java.io.Serializable interface, which means that the LinkedList supports serialization and can be transmitted by serialization.
The LinkedList is non-synchronous.
2.LinkedList Source Code Analysis 2.1 The basic structure of the node
Private Static class Node<e> { E item; // represents the value that the node contains // expresses the next node of the current node // represents the previous node of the current node Node (node<E> prev, E element, node<e> next) { this. Item = element; this. Next = next; this. prev = prev; } }
2.2 Adding operations
Public BooleanAdd (e e) {linklast (e); return true; } voidLinklast (e e) {Finalnode<e> L =Last ; FinalNode<e> NewNode =NewNode<> (L, E,NULL); Last=NewNode; if(L = =NULL) First=NewNode; ElseL.next=NewNode; Size++; Modcount++; }
Insert specified position
Public voidAddintindex, E Element) { //Check to see if it crossesCheckpositionindex (index); //The last one calls the add if(Index = =size) linklast (element); //Middle Position Call Linkbefore ElseLinkbefore (element, node (index)); }voidLinkbefore (e E, node<e>succ) { //assert succ! = null; Finalnode<e> pred =Succ.prev; FinalNode<e> NewNode =NewNode<>(Pred, E, succ); Succ.prev=NewNode; if(Pred = =NULL) First=NewNode; ElsePred.next=NewNode; Size++; Modcount++; }
LinkedList of the Java collection