|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectsdds.List<O>
sdds.DList<O>
O
- the type of object the list will holdpublic class DList<O>
A dynamic singly-linked List
.
Field Summary |
---|
Fields inherited from class sdds.List |
---|
last, length |
Constructor Summary | |
---|---|
|
DList()
Construct an empty dynamic list. |
protected |
DList(int length,
sdds.List.Node<O> last)
Construct a dynamic list with a given size and a given first node. |
|
DList(O[] elements)
Construct a dynamic list which initially contains a given set of elements. |
Method Summary | |
---|---|
DList<O> |
add(List<O> otherList)
Add every element from otherList to the dynamic list. |
DList<O> |
add(O element)
Add an element to the dynamic list in O(1) time. |
DList<O> |
add(O[] elements)
Add x elements to the dynamic list in O(x) time. |
DList<O> |
clone()
Return a deep copy of the dynamic list. |
boolean |
contains(O element)
Search the dynamic list to see if it contains a given object in O(n) time. |
boolean |
containsEquals(O element)
Search the dynamic list to see if it contains a given object in O(n) time. |
boolean |
equals(java.lang.Object other)
Check if this list is the same as another. |
O |
get(int index)
Get an arbitrary element from the dynamic list in O(n) time. |
O |
getLast()
Return the last element added to the dynamic list in O(1) time. |
java.util.Iterator<O> |
iterator()
Return an Iterator that will yield each element in the dynamic list. |
int |
length()
Return the number of elements in the dynamic list in O(1) time. |
DList<O> |
remove(O element)
Remove the first instance of a given object from the dynamic list in O(n) time. |
DList<O> |
removeAll(O element)
Remove every instance of a given object from the dynamic list in O(n) time. |
DList<O> |
removeAllEquals(O element)
Remove every instance of a given object from the dynamic list in O(n) time. |
DList<O> |
removeEquals(O element)
Remove the first instance of a given object from the dynamic list in O(n) time. |
O[] |
toArray(O[] array)
Return an array containing all the elements in the dynamic list. |
java.lang.String |
toString()
Return a string representation of this dynamic list and all its elements. |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
protected DList(int length, sdds.List.Node<O> last)
Construct a dynamic list with a given size and a given first node.
length
- the number of elements in the listlast
- the last node in the listpublic DList()
Construct an empty dynamic list.
public DList(O[] elements)
Construct a dynamic list which initially contains a given set of elements.
elements
- the elements the list will initially containMethod Detail |
---|
public int length()
Return the number of elements in the dynamic list in O(1) time.
length
in class List<O>
public DList<O> add(O element)
Add an element to the dynamic list in O(1) time.
The first element (index 0) is added first, which means that calling getLast()
on the returned list will return elements[elements.length - 1]
.
add
in class List<O>
element
- the element to be added
public DList<O> add(O[] elements)
Add x elements to the dynamic list in O(x) time.
add
in class List<O>
elements
- an array of elements to be added
public DList<O> add(List<O> otherList)
Add every element from otherList to the dynamic list.
The first element added is the first element that was added to otherList, which means result.
.getLast()
==otherList.getLast()
add
in class List<O>
otherList
- a list of elements to be added to this list
public O getLast()
Return the last element added to the dynamic list in O(1) time.
getLast
in class List<O>
public O get(int index)
Get an arbitrary element from the dynamic list in O(n) time.
get(0)
is equivalent to getLast()
.
get
in class List<O>
index
- the number of the element to be returned
length()
.public boolean contains(O element)
Search the dynamic list to see if it contains a given object in O(n) time. Objects are compared using ==
.
contains
in class List<O>
element
- the object to search for
public boolean containsEquals(O element)
Search the dynamic list to see if it contains a given object in O(n) time. Objects are compared using Object.equals(java.lang.Object)
.
containsEquals
in class List<O>
element
- the object to search for
public DList<O> remove(O element)
Remove the first instance of a given object from the dynamic list in O(n) time. Objects are compared using ==
.
remove
in class List<O>
element
- the object to remove
public DList<O> removeEquals(O element)
Remove the first instance of a given object from the dynamic list in O(n) time. Objects are compared using Object.equals(java.lang.Object)
.
removeEquals
in class List<O>
element
- the object to remove
public DList<O> removeAll(O element)
Remove every instance of a given object from the dynamic list in O(n) time. Objects are compared using ==
.
removeAll
in class List<O>
element
- the object to remove every instance of
public DList<O> removeAllEquals(O element)
Remove every instance of a given object from the dynamic list in O(n) time. Objects are compared using Object.equals(java.lang.Object)
.
removeAllEquals
in class List<O>
element
- the object to remove every instance of
public java.util.Iterator<O> iterator()
Return an Iterator
that will yield each element in the dynamic list.
The first element yielded will be the last element added to the list; the last element yielded will be the first element added to the list.
iterator
in class List<O>
public O[] toArray(O[] array)
Return an array containing all the elements in the dynamic list.
The first element in the array (index 0) will be the first element added to the list.
toArray
in class List<O>
array
- an array of type O of any length
public boolean equals(java.lang.Object other)
Check if this list is the same as another.
Two lists are considered the same if they contain the same elements in the same order. Elements are compared using Object.equals(java.lang.Object)
.
The class of the list is not taken into account. In other words, a DList
can be equal to an SList
if they contains the same elements in the same order.
equals
in class List<O>
other
- another list
public DList<O> clone()
Return a deep copy of the dynamic list.
The clone list can be modified without affecting the original.
clone
in class List<O>
public java.lang.String toString()
Return a string representation of this dynamic list and all its elements.
toString
in class List<O>
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |