public class DoublyLinkedListImpl<T extends DoublyLinkedList.Item<? extends T>> extends java.lang.Object implements DoublyLinkedList<T>
| Modifier and Type | Class and Description |
|---|---|
static class |
DoublyLinkedListImpl.Item<T extends DoublyLinkedListImpl.Item<?>> |
| Modifier and Type | Field and Description |
|---|---|
protected T |
_firstItem |
protected T |
_lastItem |
protected int |
size |
| Modifier | Constructor and Description |
|---|---|
|
DoublyLinkedListImpl()
A new list with no items.
|
protected |
DoublyLinkedListImpl(T _h,
T _t,
int size) |
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Clear this list
|
boolean |
contains(T item)
Returns true if the list contains an item i where
i.equals(item) is true. |
java.util.Enumeration<T> |
elements()
Get a
Enumeration of DoublyLinkedList.Item. |
boolean |
hasNext(T i) |
boolean |
hasPrev(T i) |
T |
head()
Returns the first item.
|
void |
insertNext(T i,
T j)
Inserts item j after item i
|
void |
insertPrev(T i,
T j)
Inserts item
j before item i. |
boolean |
isEmpty()
Check if this list is empty.
|
java.util.Iterator<T> |
iterator() |
T |
next(T i) |
T |
pop()
Removes and returns the last item.
|
DoublyLinkedList<T> |
pop(int n)
Remove n elements from tail and return them as a
DoublyLinkedList. |
T |
prev(T i) |
void |
push(T i)
Puts the item after the last item.
|
T |
remove(T i)
Remove and return a element
|
java.util.Enumeration<T> |
reverseElements() |
T |
shift()
Removes and returns the first item.
|
DoublyLinkedList<T> |
shift(int n)
Remove n elements from head and return them as a
DoublyLinkedList. |
int |
size()
Return the size of this list
|
T |
tail()
Returns the last item.
|
void |
unshift(T i)
Puts the item before the first item.
|
protected int size
protected T extends DoublyLinkedList.Item<? extends T> _firstItem
protected T extends DoublyLinkedList.Item<? extends T> _lastItem
public void clear()
clear in interface DoublyLinkedList<T extends DoublyLinkedList.Item<? extends T>>public final int size()
size in interface DoublyLinkedList<T extends DoublyLinkedList.Item<? extends T>>public final boolean isEmpty()
true if this list is empty, false otherwise.isEmpty in interface DoublyLinkedList<T extends DoublyLinkedList.Item<? extends T>>public final java.util.Enumeration<T> elements()
Enumeration of DoublyLinkedList.Item.elements in interface DoublyLinkedList<T extends DoublyLinkedList.Item<? extends T>>forwardElements()public boolean contains(T item)
DoublyLinkedListi.equals(item) is true.contains in interface DoublyLinkedList<T extends DoublyLinkedList.Item<? extends T>>public final T head()
head in interface DoublyLinkedList<T extends DoublyLinkedList.Item<? extends T>>null if emptypublic final T tail()
tail in interface DoublyLinkedList<T extends DoublyLinkedList.Item<? extends T>>null if emptypublic final void unshift(T i)
unshift in interface DoublyLinkedList<T extends DoublyLinkedList.Item<? extends T>>public final T shift()
shift in interface DoublyLinkedList<T extends DoublyLinkedList.Item<? extends T>>public DoublyLinkedList<T> shift(int n)
DoublyLinkedList.shift in interface DoublyLinkedList<T extends DoublyLinkedList.Item<? extends T>>public final void push(T i)
push in interface DoublyLinkedList<T extends DoublyLinkedList.Item<? extends T>>public final T pop()
pop in interface DoublyLinkedList<T extends DoublyLinkedList.Item<? extends T>>public DoublyLinkedList<T> pop(int n)
DoublyLinkedList.pop in interface DoublyLinkedList<T extends DoublyLinkedList.Item<? extends T>>public final boolean hasNext(T i)
hasNext in interface DoublyLinkedList<T extends DoublyLinkedList.Item<? extends T>>true if i has next item. (ie. not the last item); false otherwisepublic final boolean hasPrev(T i)
hasPrev in interface DoublyLinkedList<T extends DoublyLinkedList.Item<? extends T>>true if i has previous item. (ie. not the first item); false otherwisepublic final T next(T i)
next in interface DoublyLinkedList<T extends DoublyLinkedList.Item<? extends T>>i. If this is the last element, return nullpublic final T prev(T i)
prev in interface DoublyLinkedList<T extends DoublyLinkedList.Item<? extends T>>i. If this is the first element, return nullpublic T remove(T i)
remove in interface DoublyLinkedList<T extends DoublyLinkedList.Item<? extends T>>null if the item was not in the listpublic void insertPrev(T i, T j)
j before item i.insertPrev in interface DoublyLinkedList<T extends DoublyLinkedList.Item<? extends T>>public void insertNext(T i, T j)
j after item i
- Specified by:
insertNext in interface DoublyLinkedList<T extends DoublyLinkedList.Item<? extends T>>
-
reverseElements
public java.util.Enumeration<T> reverseElements()
- Returns:
- an Enumeration of list elements from tail to head
-
iterator
public java.util.Iterator<T> iterator()
- Specified by:
iterator in interface java.lang.Iterable<T extends DoublyLinkedList.Item<? extends T>>