Class OrderedIntSet

java.lang.Object
it.unimi.di.prog2.h18.AbstractIntSet
it.unimi.di.prog2.h18.OrderedIntSet
All Implemented Interfaces:
Iterable<Integer>

public class OrderedIntSet extends AbstractIntSet
A concrete sorted set of integers.

The iterator of this set returns the elements in ascending order.

  • Field Details

    • elements

      private final List<Integer> elements
      The set elements.
  • Constructor Details

    • OrderedIntSet

      public OrderedIntSet()
      Creates an empty set.
  • Method Details

    • max

      public int max() throws NoSuchElementException
      Returns the maximum element of this set.
      Returns:
      the maximum element of this set.
      Throws:
      NoSuchElementException - if this set is empty.
    • min

      public int min() throws NoSuchElementException
      Returns the minimum element of this set.
      Returns:
      the maximum element of this set.
      Throws:
      NoSuchElementException - if this set is empty.
    • iterator

      public Iterator<Integer> iterator()
    • insert

      public void insert(int x)
      Description copied from class: AbstractIntSet
      Adds the given element to this set.

      This method modifies the object, that is: \( S' = S \cup \{ x \} \).

      Specified by:
      insert in class AbstractIntSet
      Parameters:
      x - the element to be added.
    • remove

      public void remove(int x)
      Description copied from class: AbstractIntSet
      Removes the given element from this set.

      This method modifies the object, that is: \( S' = S \setminus \{ x \} \).

      Specified by:
      remove in class AbstractIntSet
      Parameters:
      x - the element to be removed.