public void insert(E e){
  if (e == null) {
    throw new IllegalArgumentException("Cannot insert 'null' into DoubleLinkedList.");
  }
  if (comparator == null) {
    append(e);
    return;
  }
  DoubleNode<E> newNode=new DoubleNode<E>(e);
  if (head == null) {
    head=newNode;
    last=newNode;
    size++;
    return;
  }
  size++;
  DoubleNode<E> p=head;
  while (p != null) {
    int cmp=comparator.compare(p.value,e);
    if (cmp <= 0) {
      p=p.next;
    }
 else {
      if (p == head) {
        p.prev=newNode;
        newNode.next=p;
        head=newNode;
        return;
      }
 else {
        newNode.prev=p.prev;
        p.prev.next=newNode;
        p.prev=newNode;
        newNode.next=p;
        return;
      }
    }
  }
  last.next=newNode;
  newNode.prev=last;
  last=newNode;
}

public void insert ( E e ) { if ( e == null ) { throw new IllegalArgumentException ( "Cannot insert 'null' into DoubleLinkedList." ) ; } if ( comparator == null ) { append ( e ) ; return ; } DoubleNode < E > newNode = new DoubleNode < E > ( e ) ; if ( head == null ) { head = newNode ; last = newNode ; size ++ ; return ; } size ++ ; DoubleNode < E > p = head ; while ( p != null ) { int cmp = comparator . compare ( p . value , e ) ; if ( cmp <= 0 ) { p = p . next ; } else { if ( p == head ) { p . prev = newNode ; newNode . next = p ; head = newNode ; return ; } else { newNode . prev = p . prev ; p . prev . next = newNode ; p . prev = newNode ; newNode . next = p ; return ; } } } last . next = newNode ; newNode . prev = last ; last = newNode ; }
insert an entity based upon the comparator . < p > if there is no comparator selected , then insert becomes a simple ' append ' .
