Package dsa.impl

Class SLinkedList<T>

java.lang.Object
dsa.impl.SLinkedList<T>
All Implemented Interfaces:
IList<T>

public class SLinkedList<T> extends Object implements IList<T>
  • Constructor Details

    • SLinkedList

      public SLinkedList()
  • Method Details

    • size

      public int size()
      Description copied from interface: IList
      Get the number of elements in the list.
      Specified by:
      size in interface IList<T>
      Returns:
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: IList
      Check if the list is empty.
      Specified by:
      isEmpty in interface IList<T>
      Returns:
      true if the list is empty, false otherwise.
    • first

      public IPosition<T> first()
      Description copied from interface: IList
      Get the first node in the list.
      Specified by:
      first in interface IList<T>
      Returns:
    • last

      public IPosition<T> last()
      Description copied from interface: IList
      Get the last node in the list.
      Specified by:
      last in interface IList<T>
      Returns:
    • next

      public IPosition<T> next(IPosition<T> n)
      Description copied from interface: IList
      Get the node after p in the list.
      Specified by:
      next in interface IList<T>
      Parameters:
      n -
      Returns:
    • prev

      public IPosition<T> prev(IPosition<T> n)
      Description copied from interface: IList
      Get the node before p in the list.
      Specified by:
      prev in interface IList<T>
      Parameters:
      n -
      Returns:
    • insertAfter

      public IPosition<T> insertAfter(IPosition<T> n, T e)
      Description copied from interface: IList
      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.
      Specified by:
      insertAfter in interface IList<T>
      Parameters:
      e -
      Returns:
      The node that the new element e is stored in.
    • insertBefore

      public IPosition<T> insertBefore(IPosition<T> n, T e)
      Description copied from interface: IList
      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.
      Specified by:
      insertBefore in interface IList<T>
      Parameters:
      e -
      Returns:
      The node that the new element e is stored in.
    • insertFirst

      public IPosition<T> insertFirst(T e)
      Description copied from interface: IList
      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.
      Specified by:
      insertFirst in interface IList<T>
      Parameters:
      e -
      Returns:
      The node that the new element e is stored in.
    • insertLast

      public IPosition<T> insertLast(T e)
      Description copied from interface: IList
      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.
      Specified by:
      insertLast in interface IList<T>
      Parameters:
      e -
      Returns:
      The node that the new element e is stored in.
    • remove

      public T remove(IPosition<T> n)
      Description copied from interface: IList
      Remove node p from the list.
      Specified by:
      remove in interface IList<T>
      Parameters:
      n -
      Returns:
      The element that was stored in p.
    • replace

      public T replace(IPosition<T> n, T e)
      Description copied from interface: IList
      Replace the element stored in node p with e. This does not affect the number of elements in the list.
      Specified by:
      replace in interface IList<T>
      Parameters:
      n -
      e -
      Returns:
      The element that was stored in p before the replacement.
    • iterator

      public Iterator<T> iterator()
      Description copied from interface: IList
      Get an iterator that can iterate over the list's elements.
      Specified by:
      iterator in interface IList<T>
      Returns:
      The iterator.