Package cs2110

Interface Seq<T>

All Superinterfaces:
Iterable<T>
All Known Implementing Classes:
ArraySeq, DLinkedSeq

public interface Seq<T> extends Iterable<T>
A mutable, ordered sequence of elements of type `T` with unbounded capacity. Null elements are not allowed.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    append(T elem)
    Add element `elem` to the end of this list.
    boolean
    contains(T elem)
    Return whether this list contains an element equal to `elem` (according to `equals()`).
    get(int index)
    Return the element at index `index` in this list.
    void
    insertBefore(T elem, T successor)
    Insert element `elem` into the list just before the first occurrence of element `successor`.
    void
    prepend(T elem)
    Insert element `elem` at the beginning of this list.
    boolean
    remove(T elem)
    Remove the first occurrence of element `elem` (if any) from this list.
    int
    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

      void prepend(T elem)
      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

      void append(T elem)
      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

      T get(int index)
      Return the element at index `index` in this list. The index of the first element is 0. Requires 0 <= index < size(). Will not return null.
    • contains

      boolean contains(T elem)
      Return whether this list contains an element equal to `elem` (according to `equals()`). Requires `elem` is not null.
    • insertBefore

      void insertBefore(T elem, T successor)
      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

      boolean remove(T elem)
      Remove the first occurrence of element `elem` (if any) from this list. Return whether the list changed. Requires `elem` is not null.