示例#1
0
 /**
  * Inserts the given node z before the given node v. And error occurs if v is the header
  *
  * @param v
  * @param z
  * @throws IllegalArgumentException
  */
 public void addBefore(DLNode<E> v, DLNode<E> z) throws IllegalArgumentException {
   DLNode<E> u = getPrev(v); // may throw an IllegalArgumentException
   z.setPrev(u);
   z.setNext(v);
   v.setPrev(z);
   u.setNext(z);
   self.size++;
 }
示例#2
0
 /**
  * Inserts the given node z after the given node v. And error occurs if v is the trailer
  *
  * @param v
  * @param z
  * @throws IllegalArgumentException
  */
 public void addAfter(DLNode<E> v, DLNode<E> z) throws IllegalArgumentException {
   DLNode<E> w = getNext(v); // may throw an IllegalArgumentException
   z.setPrev(v);
   z.setNext(w);
   w.setPrev(z);
   v.setNext(z);
   self.size++;
 }
示例#3
0
  /**
   * Removes the given node v from the list. An error occurs if v is the header or tailer
   *
   * @param v
   */
  public void remove(DLNode<E> v) {
    DLNode<E> u = self.getPrev(v); // may throw an IllegalArgumentException
    DLNode<E> w = self.getNext(v); // may throw an IllegalArgumentException

    // unlink the node from the list
    w.setPrev(u);
    u.setNext(w);
    v.setPrev(null);
    v.setNext(null);
    self.size--;
  }