com.mhhe.clrs2e
Class SentinelDLLDictionary

java.lang.Object
  |
  +--com.mhhe.clrs2e.LinkedList
        |
        +--com.mhhe.clrs2e.SentinelDLL
              |
              +--com.mhhe.clrs2e.SentinelDLLDictionary
All Implemented Interfaces:
Dictionary
Direct Known Subclasses:
SortableSentinelDLL

public class SentinelDLLDictionary
extends SentinelDLL
implements Dictionary

A circular, doubly linked list with a sentinel with a search method. Requires all elements inserted to implement the Comparable interface.


Nested Class Summary
 
Nested classes inherited from class com.mhhe.clrs2e.SentinelDLL
SentinelDLL.SentinelDLLIterator
 
Nested classes inherited from class com.mhhe.clrs2e.LinkedList
LinkedList.ListIterator, LinkedList.Node
 
Field Summary
 
Fields inherited from class com.mhhe.clrs2e.SentinelDLL
nil
 
Constructor Summary
SentinelDLLDictionary()
           
 
Method Summary
 java.lang.Object insert(java.lang.Comparable o)
          Inserts an element at the head of the list.
 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.
 java.lang.Object search(java.lang.Comparable k)
          Searches for an element with a given key.
 
Methods inherited from class com.mhhe.clrs2e.SentinelDLL
concatenate, delete, isEmpty, iterator
 
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
 
Methods inherited from interface com.mhhe.clrs2e.Dictionary
delete
 

Constructor Detail

SentinelDLLDictionary

public SentinelDLLDictionary()
Method Detail

insert

public java.lang.Object insert(java.lang.Comparable o)
Inserts an element at the head of the list. This form of insert is required by the Dictionary interface.

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

insert

public java.lang.Object insert(java.lang.Object o)
Inserts an element at the head of the list. The element inserted must be an object that implements the Comparable interface.

Overrides:
insert in class SentinelDLL
Parameters:
o - The element to be inserted.
Returns:
A handle to the new element.
Throws:
java.lang.ClassCastException - if the element does not implement Comparable.

insertAfter

public java.lang.Object insertAfter(java.lang.Object o,
                                    java.lang.Object after)
Inserts an element after a given element. The element inserted must be an object that implements the Comparable interface.

Overrides:
insertAfter in class SentinelDLL
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.
Throws:
java.lang.ClassCastException - if the element does not implement Comparable.

insertAtTail

public java.lang.Object insertAtTail(java.lang.Object o)
Inserts an element at the tail of the list. The element inserted must be an object that implements the Comparable interface.

Overrides:
insertAtTail in class SentinelDLL
Parameters:
o - The element to be inserted.
Returns:
A handle to the new element.
Throws:
java.lang.ClassCastException - if the element does not implement Comparable.

search

public java.lang.Object search(java.lang.Comparable k)
Searches for an element with a given key.

Specified by:
search in interface Dictionary
Parameters:
k - The key being searched for.
Returns:
A handle to the object found, or null if there is no match.