com.mhhe.clrs2e
Class LinkedList

java.lang.Object
  |
  +--com.mhhe.clrs2e.LinkedList
Direct Known Subclasses:
LinearDLL, SentinelDLL

public abstract class LinkedList
extends java.lang.Object

Abstract class for a doubly linked list in Section 10.2 of Introduction to Algorithms, Second edition.


Nested Class Summary
 class LinkedList.ListIterator
          Abstract inner class for an iterator.
protected static class LinkedList.Node
          Inner class for nodes of a linked list.
 
Constructor Summary
LinkedList()
           
 
Method Summary
abstract  void concatenate(com.mhhe.clrs2e.LinkedList l)
          Concatenates another linked list onto the end of this list, destroying the other linked list.
abstract  void delete(java.lang.Object handle)
          Removes an element.
static java.lang.Object dereference(java.lang.Object node)
          Returns the object stored in a node.
abstract  java.lang.Object insert(java.lang.Object o)
          Inserts an element at the head of the list.
abstract  java.lang.Object insertAfter(java.lang.Object o, java.lang.Object after)
          Inserts an element after a given element.
abstract  boolean isEmpty()
          Returns true if this list is empty, false otherwise.
abstract  java.util.Iterator iterator()
          Creates and returns an Iterator object for this list.
 void toArray(java.lang.Object[] array)
          Copies each element of this list into an array.
 java.lang.String toString()
          Returns the String representation of this list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LinkedList

public LinkedList()
Method Detail

dereference

public static java.lang.Object dereference(java.lang.Object node)
Returns the object stored in a node.

Parameters:
node - The node.
Throws:
java.lang.ClassCastException - if node does not reference a Node object.

insert

public abstract java.lang.Object insert(java.lang.Object o)
Inserts an element at the head of the list.

Parameters:
o - The element to be inserted.
Returns:
A handle to the new element.

insertAfter

public abstract java.lang.Object insertAfter(java.lang.Object o,
                                             java.lang.Object after)
Inserts an element after a given element.

Parameters:
o - The element to be inserted.
after - The element after which the new element is to be inserted. If null, the new element is inserted at the head of the list.
Returns:
A handle to the new element.

delete

public abstract void delete(java.lang.Object handle)
Removes an element.

Parameters:
handle - Handle to the element to remove.

isEmpty

public abstract boolean isEmpty()
Returns true if this list is empty, false otherwise.


iterator

public abstract java.util.Iterator iterator()
Creates and returns an Iterator object for this list.


concatenate

public abstract void concatenate(com.mhhe.clrs2e.LinkedList l)
Concatenates another linked list onto the end of this list, destroying the other linked list.

Parameters:
l - The linked list to be concatenated onto the end of this list.

toString

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

Overrides:
toString in class java.lang.Object

toArray

public void toArray(java.lang.Object[] array)
Copies each element of this list into an array.

Parameters:
array - The array, assumed to be already allocated.