Class MaxIntSet

java.lang.Object
it.unimi.di.prog2.h13.ArrayIntSet
it.unimi.di.prog2.h16.MaxIntSet
All Implemented Interfaces:
Iterable<Integer>

public class MaxIntSet extends ArrayIntSet
Example of MaxIntSet taken from section 7.4 of the textbook by Liskov et al..

Note: this class extends ArrayIntSet.

  • Field Details

    • biggest

      private int biggest
      The biggest element, if set is not empty.
  • Constructor Details

    • MaxIntSet

      public MaxIntSet()
      Construct an empty MaxIntSet.
  • Method Details

    • insert

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

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

      Overrides:
      insert in class ArrayIntSet
      Parameters:
      x - the element to be added.
    • remove

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

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

      Overrides:
      remove in class ArrayIntSet
      Parameters:
      x - the element to be removed.
    • max

      public int max() throws NoSuchElementException
      Returns the maximum value in the set, or raises IllegalStateException otherwise.
      Returns:
      the maximum value in the set.
      Throws:
      NoSuchElementException - if the set is empty.
    • toString

      public String toString()
      Overrides:
      toString in class ArrayIntSet