Two, LinkList resolve its source

1. Introduction list

Chain unit is a physically non-continuous, non-sequential storage structure. Sister chain by a series of dots, the node can run
dynamically generated. Each node consists of two parts, a data field for storing data elements, a node is a next storage pointer field

Doubly linked list is a linked list, each node has both precursor pointer, a pointer drive has the

Analysis 2.LinkList source
1) Constructors
public LinkList () {
}

public LinkedList(Collection <? extend E> c){
this();
addAll(c)
}

2) elements into
a first inserted
public Boolean the Add (E E) {
linkLast (E);
return to true;
}

// the last location in the linked list node insertion
void linkLast (E E) {
//
Final the Node <E> L = Last;
// Construct a new node, (l (precursor node), e (a new node elements), null (successor node));
Final the node <E> the newNode = new new the node <> (L, E, null);
set a new node is tail node
last = newNode;
determining whether the list has nodes
if ( == null L)

First the newNode =;
the else
// set the end node successor node is a new node
l.next = the newNode;
size ++;
ModCount ++;
}

// linked list of nodes defined classes
Private static class the Node <E> {
E Item;
the Node <E> Next;
the Node <E> PREV;

Node(Node<E> prev, E element, Node<E> next) {
this.item = element;
this.next = next;
this.prev = prev;
}
}


The second embodiment is inserted
public Boolean the Add (E e.int index) {
}


3) Remove element
public E Remove () {
}

public E remove(int index){
}


4) Find Method
public GET E (int index) {
checkElementIndex (index);
return Node (index) .Item;
}


Traversing 5) the list
iterators the LinkedList
Iterator <String> iterator = list.iterator ( );

=================================================
3 the main method of
1) to add elements to the LinkedList
the LinkedList provides a method for adding a plurality of elements:
● Boolean the Add (E E)
add an element to the tail of the linked list, if successful, returns true, otherwise returns false.

● void addFirst (E e)
is inserted into the head of a linked list element.

● addLast (E e)
add an element to the tail of the linked list.

● void add (int index, E element)
to insert an element at the specified location.

 

2) To remove elements from LinkedList
LinkedList provides a number of methods to remove elements:

● E remove (int index)
is removed from the element at the location of the current list.

● E removeFirst ()
removes the first element from the list of current

● E removeLast ()
removes the last element from the current list.

● E remove ()
removes the first element from the current list in the same removeLast () the same.

 

3) Get elements from the LinkedList
LinkedList provides a method for obtaining a plurality of elements:

● E get (int index)
Gets the specified location from the current list of elements.

● E getFirst ()
Gets the first element from the current list.

● E getLast ()
Gets the last element from the current list.

 

4)LinkedList的遍历方法
Iterator it =list.lterator();
while(it.hasNext()){
E e=it.next();
it=it.next();
}

foreach statement is the most efficient, followed by the iterator, the worst efficiency is the for loop


Summary: Data Structure inkedList storage element is doubly linked list structure, connected by a node from the storage element,
a reference node of each node contains the front, and the reference value stored in the nodes of a node.

Guess you like

Origin www.cnblogs.com/houchen/p/11665475.html