Interface DynamicSequence<Item>

Type Parameters:
Item - the item type
All Superinterfaces:
Container<Item>, Iterable<Item>, StaticSequence<Item>
All Known Subinterfaces:
LinkedList<Item>
All Known Implementing Classes:
CircularDynamicArray, CircularDynamicArray, DoublyLinkedList, DoublyLinkedList, DynamicArray, DynamicArray, SinglyLinkedList, SinglyLinkedList, StaticArray, StaticArray

public interface DynamicSequence<Item> extends StaticSequence<Item>
A dynamic sequence.

A sequence that can have items inserted into or removed from it; these operations change (increment or decrement) the size of the dynamic sequence.

  • Method Details

    • insert

      void insert(int index, Item item) throws IndexOutOfBoundsException
      Insert the given item at the given index.

      Increments the size, as well as the indices of all items that had the same index or higher.

      Parameters:
      index - the index
      item - the new item
      Throws:
      IndexOutOfBoundsException - if index < 0 or index > n (where n is the size)
    • remove

      Item remove(int index) throws IndexOutOfBoundsException
      Remove and return the item at the given index.

      Decrements the size, as well as the indices of all items that had the same index or higher.

      Parameters:
      index - the index
      Returns:
      the item that was at that index
      Throws:
      IndexOutOfBoundsException - if index < 0 or index >= n (where n is the size)
    • insertFirst

      default void insertFirst(Item item)
      Insert the given item as the first.

      Increments the size, as well as the indices of all the other items.

      Parameters:
      item - the new item that should now be at index 0
    • insertLast

      default void insertLast(Item item)
      Insert the given item as the last.

      Increments the size.

      Parameters:
      item - the new item that should now be at index n (where n is the old size)
    • removeFirst

      default Item removeFirst() throws NoSuchElementException
      Remove and return the first item.

      Decrements the size, as well as the indices of all the other items.

      Returns:
      the old item that was at index 0
      Throws:
      NoSuchElementException - if there's no first item to remove (i.e. this is empty)
    • removeLast

      default Item removeLast() throws NoSuchElementException
      Remove and return the last item.

      Decrements the size.

      Returns:
      the old item that was at index n-1 (where n is the old size)
      Throws:
      NoSuchElementException - if there's no last item to remove (i.e. this is empty)