LinkedList的底层是一个不带头的双向链表。
不带头双向链表中的每一个节点有三个域:值域,上一个节点的域,下一个节点的域。

不带头双向链表的实现:
public class Mylinkdelist{//定义一个内部类(节点)static class ListNode{int val;//值域ListNode prev;//指向前一个节点ListNode next;//指向后一个节点public ListNode(int val){//构造方法this.val=val;}}ListNode head=null;//定义一个头结点ListNode last=null;//定义一个尾链表public void addIndex(int Index,int data){//从指定位置插入int len=size();if(Index<0||Index>len){return ;}ListNode node = new ListNode (data); if(Index==0){addFirst(data);return ;}if(Index==len){addLast(data);return;}ListNode cur=head;int count=0;while(count!=Index){count++;cur=cur.next;}node.next=cur;node.prev=cur.prev;cur.prev.next=node;cur.prev=node;}public void addLast(int key){//尾插ListNode node=new ListNode(key);if(last==null){head=last=noed;}else{last.next=node;node.prev=last;last=node;}}public void addFirst(int key){//头插ListNode node=new ListNode(key);if(head==null){head=last=node;}else{node.next=head;head.prev=node;head=node;}} public void diaplay(){//把双向链表展示出来ListNode cur=head;while(cur!=null){//用cur遍历链表System.out.print(cur.val+" ");cur=cur.next;}}public int size(){//求链表的长度ListNode cur=head;int count=0;while(cur!=null){cur=cur.next;count++:}return count;}public boolean contains(int key){//查找ListNode cur=head;while(cur!=null){if(cur.val==key){return true;}cur=cur.next;}return false;}public void remove(int key){//删除节点ListNode cur=head;while(cur!=null){if(cur.val==key){if(cur==head){head=head.next;if(head==null){head.prev=null;}}else{cur.prev.next=cur.next;if(cur.next==null){last=cur;}cur.next.prev=cur.prev;}}cur=cur.next;}}public void clear(){//清除链表ListNode cur=head;while(cur!=null){ListNode curN=cur.next;cur.next=null;cur.prev=null;cur=curN;}head=last=null;}
}