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.
|
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 java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
SentinelDLLDictionary
public SentinelDLLDictionary()
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.