Пример #1
0
 /**
  * Remove the supplied node
  *
  * @param n The node to be removed
  * @return Whether node was removed (If it returns false, the node does not exist in the list)
  */
 private boolean removeNode(DoubleNode<E> n) {
   if (contains(n)) {
     n.getPrev().setNext(n.getNext());
     n.getNext().setPrev(n.getPrev());
     n = null;
     size--;
     return true;
   }
   return false;
 }
Пример #2
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++;
 }
Пример #3
0
 /**
  * Get the node with the highest value in the list
  *
  * @return The node with the highest item value
  */
 private DoubleNode<E> highest() {
   DoubleNode<E> highest = head.getNext();
   Iterator<DoubleNode<E>> i = nodeIterator();
   while (i.hasNext()) {
     DoubleNode<E> current = i.next();
     if (current.getValue().compareTo(highest.getValue()) > 0) {
       highest = current;
     }
   }
   return highest;
 }
Пример #4
0
 /**
  * Get the first item in the list
  *
  * @return The first item in the list
  */
 public E getFirst() {
   return head.getNext().getValue();
 }