linkedLists
Class DList

java.lang.Object
  extended by linkedLists.DList

public class DList
extends java.lang.Object

Doubly liked list with nodes of type DNode storing strings


Constructor Summary
DList()
          Constructor that creates an empty list
 
Method Summary
 void addAfter(DNode v, DNode z)
          Inserts the given node z after the given node v.
 void addBefore(DNode v, DNode z)
          Inserts the given node z before the given node v.
 void addFirst(DNode v)
          Inserts the given node at the head of the list
 void addLast(DNode v)
          Inserts the given node at the tail of the list
 DNode getFirst()
          Returns the first node of the list
 DNode getLast()
          Returns the last node of the list
 DNode getNext(DNode v)
          Returns the node after the given node v.
 DNode getPrev(DNode v)
          Returns the node before the given node v.
 boolean hasNext(DNode v)
          Returns whether a given node has a next node
 boolean hasPrev(DNode v)
          Returns whether a given node has a previous node
 boolean isEmpty()
          Returns whether the list is empty
 void remove(DNode v)
          Removes the given node v from the list.
 int size()
          Returns the number of elements in the list
static void sort(DList L)
          Insertion-sort for a doubly linked list of class DList
 java.lang.String toString()
          Returns a string representation of the list
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DList

public DList()
Constructor that creates an empty list

Method Detail

size

public int size()
Returns the number of elements in the list


isEmpty

public boolean isEmpty()
Returns whether the list is empty


getFirst

public DNode getFirst()
               throws java.lang.IllegalStateException
Returns the first node of the list

Throws:
java.lang.IllegalStateException

getLast

public DNode getLast()
              throws java.lang.IllegalStateException
Returns the last node of the list

Throws:
java.lang.IllegalStateException

getPrev

public DNode getPrev(DNode v)
              throws java.lang.IllegalArgumentException
Returns the node before the given node v. Error if v is the header

Throws:
java.lang.IllegalArgumentException

getNext

public DNode getNext(DNode v)
              throws java.lang.IllegalArgumentException
Returns the node after the given node v. An error occurs if v is the trailer

Throws:
java.lang.IllegalArgumentException

addBefore

public void addBefore(DNode v,
                      DNode z)
               throws java.lang.IllegalArgumentException
Inserts the given node z before the given node v. An error occurs if v is the header

Throws:
java.lang.IllegalArgumentException

addAfter

public void addAfter(DNode v,
                     DNode z)
Inserts the given node z after the given node v. An error occurs if v is the trailer


addFirst

public void addFirst(DNode v)
Inserts the given node at the head of the list


addLast

public void addLast(DNode v)
Inserts the given node at the tail of the list


remove

public void remove(DNode v)
Removes the given node v from the list. An error occurs if v is the header or the trailer


hasPrev

public boolean hasPrev(DNode v)
Returns whether a given node has a previous node


hasNext

public boolean hasNext(DNode v)
Returns whether a given node has a next node


toString

public java.lang.String toString()
Returns a string representation of the list

Overrides:
toString in class java.lang.Object

sort

public static void sort(DList L)
Insertion-sort for a doubly linked list of class DList