Package cs2110
Interface Seq<T>
- All Superinterfaces:
Iterable<T>
- All Known Implementing Classes:
ArraySeq,DLinkedSeq
A mutable, ordered sequence of elements of type `T` with unbounded capacity. Null elements are
not allowed.
-
Method Summary
Modifier and TypeMethodDescriptionvoidAdd element `elem` to the end of this list.booleanReturn whether this list contains an element equal to `elem` (according to `equals()`).get(int index) Return the element at index `index` in this list.voidinsertBefore(T elem, T successor) Insert element `elem` into the list just before the first occurrence of element `successor`.voidInsert element `elem` at the beginning of this list.booleanRemove the first occurrence of element `elem` (if any) from this list.intsize()Return the number of elements in this list.Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
Method Details
-
size
int size()Return the number of elements in this list. -
prepend
Insert element `elem` at the beginning of this list. Example: if the list is [8, 7, 4], prepend(2) would change the list to [2, 8, 7, 4]. Requires `elem` is not null. -
append
Add element `elem` to the end of this list. Example: if the list is [8, 7, 4], append(2) would change the list to [8, 7, 4, 2]. Requires `elem` is not null. -
get
Return the element at index `index` in this list. The index of the first element is 0. Requires0 <= index < size(). Will not return null. -
contains
Return whether this list contains an element equal to `elem` (according to `equals()`). Requires `elem` is not null. -
insertBefore
Insert element `elem` into the list just before the first occurrence of element `successor`. Requires that `successor` is contained in the list and that `elem` and `successor` are not null.Example: If the list is [3, 8, 2], then insertBefore(1, 8) would change the list to [3, 1, 8, 2].
-
remove
Remove the first occurrence of element `elem` (if any) from this list. Return whether the list changed. Requires `elem` is not null.
-