Package dsa.iface

Interface IList<T>

All Known Implementing Classes:
SLinkedList

public interface IList<T>
ADT to represent a List data structure. Also known as a "Sequence" data structure.
  • Method Details

    • size

      int size()
      Get the number of elements in the list.
      Returns:
    • isEmpty

      boolean isEmpty()
      Check if the list is empty.
      Returns:
      true if the list is empty, false otherwise.
    • first

      IPosition<T> first()
      Get the first node in the list.
      Returns:
    • last

      IPosition<T> last()
      Get the last node in the list.
      Returns:
    • prev

      IPosition<T> prev(IPosition<T> p)
      Get the node before p in the list.
      Parameters:
      p -
      Returns:
    • next

      IPosition<T> next(IPosition<T> p)
      Get the node after p in the list.
      Parameters:
      p -
      Returns:
    • insertFirst

      IPosition<T> insertFirst(T e)
      Insert element e as the first element of the list. A new node will be created at the start of the list, which will have e as its element. This node will be placed before any existing first node.
      Parameters:
      e -
      Returns:
      The node that the new element e is stored in.
    • insertLast

      IPosition<T> insertLast(T e)
      Insert element e as the last element of the list. A new node will be created at the end of the list, which will have e as its element. This node will be placed after any existing last node.
      Parameters:
      e -
      Returns:
      The node that the new element e is stored in.
    • insertBefore

      IPosition<T> insertBefore(IPosition<T> p, T e)
      Insert element e into the list in the position before node p. A new node will be created, which will have e as its element. This node will be placed before node p. If p was not the first node in the list, the new node will be placed between p and the node before it.
      Parameters:
      e -
      Returns:
      The node that the new element e is stored in.
    • insertAfter

      IPosition<T> insertAfter(IPosition<T> p, T e)
      Insert element e into the list in the position after node p. A new node will be created, which will have e as its element. This node will be placed after node p. If p was not the last node in the list, the new node will be placed between p and the node after it.
      Parameters:
      e -
      Returns:
      The node that the new element e is stored in.
    • replace

      T replace(IPosition<T> p, T e)
      Replace the element stored in node p with e. This does not affect the number of elements in the list.
      Parameters:
      p -
      e -
      Returns:
      The element that was stored in p before the replacement.
    • remove

      T remove(IPosition<T> p)
      Remove node p from the list.
      Parameters:
      p -
      Returns:
      The element that was stored in p.
    • iterator

      Iterator<T> iterator()
      Get an iterator that can iterate over the list's elements.
      Returns:
      The iterator.