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;}
}