com.mhhe.clrs2e
Class SentinelDLL

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

public class SentinelDLL
extends LinkedList

A circular, doubly linked list with a sentinel from pages 206-207 of Introduction to Algorithms, Second edition.


Nested Class Summary
 class SentinelDLL.SentinelDLLIterator
          Inner class for an iterator.
 
Nested classes inherited from class com.mhhe.clrs2e.LinkedList
LinkedList.Node
 
Field Summary
protected  LinkedList.Node nil
          The sentinel.
 
Constructor Summary
SentinelDLL()
          Makes an empty list, consisting of only the sentinel.
 
Method Summary
 void concatenate(com.mhhe.clrs2e.LinkedList l)
          Concatenates another linked list onto the end of this list, destroying the other linked list.
 void delete(java.lang.Object handle)
          Removes an element.
 java.lang.Object insert(java.lang.Object o)
          Inserts an element at the head of the list.
 java.lang.Object insertAfter(java.lang.Object o, java.lang.Object after)
          Inserts an element after a given element.
 java.lang.Object insertAtTail(java.lang.Object o)
          Inserts an element at the tail of the list.
 boolean isEmpty()
          Returns true if this list is empty, false otherwise.
 java.util.Iterator iterator()
          Creates and returns an Iterator object for this list.
 
Methods inherited from class com.mhhe.clrs2e.LinkedList
dereference, toArray, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

nil

protected final LinkedList.Node nil
The sentinel.

Constructor Detail

SentinelDLL

public SentinelDLL()
Makes an empty list, consisting of only the sentinel.

Method Detail

insert

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

Specified by:
insert in class LinkedList
Parameters:
o - The element to be inserted.
Returns:
A handle to the new element.

insertAfter

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

Specified by:
insertAfter in class LinkedList
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.

insertAtTail

public java.lang.Object insertAtTail(java.lang.Object o)
Inserts an element at the tail of the list.

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

delete

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

Specified by:
delete in class LinkedList
Parameters:
handle - Handle to the element to remove.
Throws:
DeleteSentinelException - if handle references the sentinel nil.

isEmpty

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

Specified by:
isEmpty in class LinkedList

iterator

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

Specified by:
iterator in class LinkedList

concatenate

public void concatenate(com.mhhe.clrs2e.LinkedList l)
Description copied from class: LinkedList
Concatenates another linked list onto the end of this list, destroying the other linked list.

Specified by:
concatenate in class LinkedList
Parameters:
l - The linked list to be concatenated onto the end of this list.