예제 #1
0
 /**
  * Add an item before the supplied node
  *
  * @param node The node to add before
  * @param value The value to add
  */
 private void addBefore(DoubleNode<E> node, E value) {
   if (node == head) {
     throw new IllegalArgumentException("Cannot add node before head");
   }
   DoubleNode<E> n = new DoubleNode<>(value);
   node.getPrev().setNext(n);
   n.setPrev(node.getPrev());
   node.setPrev(n);
   n.setNext(node);
   size++;
 }
예제 #2
0
 /** Constructor */
 public DoubleList() {
   head = new DoubleNode<>(null);
   tail = new DoubleNode<>(null);
   head.setNext(tail);
   tail.setPrev(head);
   size = 0;
 }
예제 #3
0
 /**
  * Add an item after the supplied node
  *
  * @param node The node to add after
  * @param value The value to add
  */
 private void addAfter(DoubleNode<E> node, E value) {
   if (node == tail) {
     throw new IllegalArgumentException("Cannot add node after tail");
   }
   DoubleNode<E> n = new DoubleNode<>(value);
   node.getNext().setPrev(n);
   n.setNext(node.getNext());
   node.setNext(n);
   n.setPrev(node);
   size++;
 }