|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectdata_structures.List<O>
data_structures.SList<O>
O
- the type of object the list will holdpublic class SList<O>
A static singly-linked List
.
Field Summary |
---|
Fields inherited from class data_structures.List |
---|
first, length |
Constructor Summary | |
---|---|
|
SList()
Construct an empty static list. |
protected |
SList(int length,
data_structures.List.Node<O> first)
Construct a static list with a given size and a given first node. |
|
SList(O[] elements)
Construct a static list which initially contains a given set of elements. |
Method Summary | |
---|---|
SList<O> |
add(List<O> otherList)
Add every element from otherList to the static list. |
SList<O> |
add(O element)
Add an element to the static list in O(1) time. |
SList<O> |
add(O[] elements)
Add x elements to the static list in O(x) time. |
SList<O> |
clone()
Return a deep copy of the dynamic list. |
protected SList<O> |
makeList(int length,
data_structures.List.Node<O> first)
This protected method is used instead of a constructor to create new lists when this list is modified. |
SList<O> |
remove(O element)
Remove the first instance of a given object from the static list in O(n) time. |
SList<O> |
removeAll(O element)
Remove every instance of a given object from the static list in O(n) time. |
SList<O> |
removeAllEquals(O element)
Remove every instance of a given object from the list in O(n) time. |
SList<O> |
removeEquals(O element)
Remove the first instance of a given object from the static list in O(n) time. |
Methods inherited from class data_structures.List |
---|
contains, containsEquals, equals, get, getLast, iterator, length, toArray, toString |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
protected SList(int length, data_structures.List.Node<O> first)
Construct a static list with a given size and a given first node.
length
- the number of elements in the listfirst
- the first node in the listpublic SList()
Construct an empty static list.
public SList(O[] elements)
Construct a static list which initially contains a given set of elements.
This constructor is more efficient in both time and space than creating an empty static list and then adding the elements to it.
elements
- the elements the list will initially containMethod Detail |
---|
protected SList<O> makeList(int length, data_structures.List.Node<O> first)
This protected method is used instead of a constructor to create new lists when this list is modified.
All subclasses of SList should use this method instead of a constructor.
This method can be overridden in a subclass and made to return objects of the subclass's type.
This avoids the new to re-write the modifying methods such as add(O)
and remove(O)
in every subclass.
length
- the number of elements in the listfirst
- the first node in the listpublic SList<O> add(O element)
Add an element to the static list in O(1) time.
The first element (index 0) is added first, which means that calling List.getLast()
on the returned list will return elements[elements.length - 1]
.
add
in class List<O>
element
- the element to be added
public SList<O> add(O[] elements)
Add x elements to the static list in O(x) time.
This method is only marginally more efficient than multiple calls to add(O)
and is provided for convenience only.
add
in class List<O>
elements
- an array of elements to be added
public SList<O> add(List<O> otherList)
Add every element from otherList to the static list.
The first element added is the first element that was added to otherList, which means result.
.List.getLast()
==otherList.List.getLast()
add
in class List<O>
otherList
- a list of elements to be added to this list
public SList<O> remove(O element)
Remove the first instance of a given object from the static list in O(n) time. Objects are compared using ==
.
remove
in class List<O>
element
- the object to remove
public SList<O> removeEquals(O element)
Remove the first instance of a given object from the static 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 SList<O> removeAll(O element)
Remove every instance of a given object from the static list in O(n) time. Objects are compared using ==
.
This method is more time efficient than multiple calls to remove(O)
.
removeAll
in class List<O>
element
- the object to remove every instance of
public SList<O> removeAllEquals(O element)
Remove every instance of a given object from the list in O(n) time. Objects are compared using Object.equals(java.lang.Object)
.
This method is more time efficient than multiple calls to removeEquals(O)
.
removeAllEquals
in class List<O>
element
- the object to remove every instance of
public SList<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>
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |