## 双向循环链表和单链表

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author Lindily
*/

int size = 0;
Node<E> head = new Node(null, null, null);

}

//核心 循环双向链表
newNode.previous.next = newNode;    //调整，新节点的前一个的后一个
newNode.next.previous = newNode;    //调整，新节点的后一个的前一个
size++;
}

public Node get(int index) {
if (index < 0 || index >= size) {
throw new IndexOutOfBoundsException("Index:" + index + ",size:" + size);
}
if (index < (size >> 1)) {          //index转为二进制带符号向右移动一个bit，相当于index/2
node = node.next;           //对头结点进行迭代
}
}else{
for(int i=size;i>index;i--){
node=node.previous;
}
}
return node;
}

public int size() {
return size;
}

public static void main(String[] args) {
for (int i = 0; i < list.size; i++) {
System.out.println(list.get(i).node);
}
}
}

class Node<E> {

E node;
Node<E> next;
Node<E> previous;

public Node(Node<E> previous, E node, Node<E> next) {
this.node = node;
this.next = next;
this.previous = previous;
}
}

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author Lindily
*/

int size = 0;

}

if (size == 0) {
head = tail = new Node<T>(node, null);
} else {
tail.next = new Node<T>(node, null);
tail = tail.next;
}
size++;
}

public Node<T> get(int index) {
if (index < 0 || index >= size) {
throw new IndexOutOfBoundsException("Index:" + index + ",size:" + size);
}
node = node.next;           //对头结点进行迭代
}
return node;
}

public int size(){
return size;
}

public static void main(String[] args){
for(int i=0;i<list.size();i++){
System.out.println(list.get(i).node);
}
}
}

class Node<T> {

T node;
Node<T> next;

public Node(T node, Node next) {
this.node = node;
this.next = next;
}
}