Beispiel #1
0
  public void clear() {
    // set head's next to the tail
    head.setNext(tail);
    head.setPrev(null);

    // set tails prev to the head
    tail.setPrev(head);
    tail.setNext(null);
    numElements = 0;
  }
Beispiel #2
0
 public void add(E s) {
   MyLinkedNode<E> newNext = tail;
   MyLinkedNode<E> newPrev = tail.getPrev();
   MyLinkedNode<E> newNode = new MyLinkedNode<E>(s);
   newNext.setPrev(newNode);
   newNode.setPrev(newPrev);
   newPrev.setNext(newNode);
   newNode.setNext(newNext);
   numElements++;
 }
Beispiel #3
0
 public void add(int i, E s) {
   MyLinkedNode<E> prevNode = head;
   MyLinkedNode<E> newNode = new MyLinkedNode<E>(s);
   for (int j = 0; j <= i + 1; j++) {
     prevNode = prevNode.getNext();
   }
   MyLinkedNode<E> nextNode = prevNode.getNext();
   newNode.setPrev(prevNode);
   newNode.setNext(nextNode);
   nextNode.setPrev(newNode);
   numElements++;
 }