public class LinkedList{ public int size; Node head, tail; private class Node { Node(X _data){ data=_data; } X data; Node next; Node pre; } // Constructor to create an empty list public LinkedList( ){ size=0; } // Add x at position i public void insert(int i, T x) { if(i<0 || i>=size){ throw new IndexOutOfBoundsException("shit this is out of bound: "+i); } Node n=this.head; for(int j=0;j m=new Node(x); m.pre=n; m.next=n.next; n.next=m; if(m.next!=null) m.next.pre=m; // if(n==tail) tail=m; size++; } //Add x at the end public void add(T x) { Node n=new Node(x); if(tail!=null) { tail.next=n; n.pre=tail; tail=n; } else{ head=tail=n; } size++; } //get the i-th element public T get(int i) { if(i<0 || i>=size) return null; Node n=this.head; for(int j=0;j=size){ throw new IndexOutOfBoundsException("shit this is out of bound: "+i); } Node n=this.head; for(int j=0;j=size){ throw new IndexOutOfBoundsException("shit this is out of bound: "+i); } Node n=this.head; for(int j=0;j