Example #1
0
 /**
  * Adds a node to the beginning of the list.
  *
  * @param node the node to add to the beginning of the list.
  */
 public LinkedListNode addFirst(LinkedListNode node) {
   node.next = head.next;
   node.previous = head;
   node.previous.next = node;
   node.next.previous = node;
   return node;
 }
Example #2
0
  /** Erases all elements in the list and re-initializes it. */
  public void clear() {
    // Remove all references in the list.
    LinkedListNode node = getLast();
    while (node != null) {
      node.remove();
      node = getLast();
    }

    // Re-initialize.
    head.next = head.previous = head;
  }
Example #3
0
 /** Creates a new linked list. */
 public LinkedList() {
   head.next = head.previous = head;
 }
Example #4
0
 /** Removes this node from the linked list that it is a part of. */
 public void remove() {
   previous.next = next;
   next.previous = previous;
 }