Class MaxIntSet
java.lang.Object
it.unimi.di.prog2.h13.ArrayIntSet
it.unimi.di.prog2.h16.MaxIntSet
Example of
MaxIntSet taken from section 7.4 of the textbook by Liskov et al..
Note: this class extends ArrayIntSet.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Methods inherited from interface Iterable
forEach, spliterator
-
Field Details
-
biggest
private int biggestThe biggest element, if set is not empty.
-
-
Constructor Details
-
MaxIntSet
public MaxIntSet()Construct an emptyMaxIntSet.
-
-
Method Details
-
insert
public void insert(int x) Description copied from class:ArrayIntSetAdds the given element to this set.This method modifies the object, that is: \( S' = S \cup \{ x \} \).
- Overrides:
insertin classArrayIntSet- Parameters:
x- the element to be added.
-
remove
public void remove(int x) Description copied from class:ArrayIntSetRemoves the given element from this set.This method modifies the object, that is: \( S' = S \setminus \{ x \} \).
- Overrides:
removein classArrayIntSet- Parameters:
x- the element to be removed.
-
max
Returns the maximum value in the set, or raisesIllegalStateExceptionotherwise.- Returns:
- the maximum value in the set.
- Throws:
NoSuchElementException- if the set is empty.
-
toString
- Overrides:
toStringin classArrayIntSet
-