Package it.unimi.di.prog2.h18.refactored
Class OrderedIntSet
java.lang.Object
it.unimi.di.prog2.h18.refactored.AbstractIntSet
it.unimi.di.prog2.h18.refactored.ListBasedAbstractIntSet
it.unimi.di.prog2.h18.refactored.OrderedIntSet
A concrete sorted set of integers.
The iterator of this set returns the elements in ascending order.
-
Field Summary
Fields inherited from class it.unimi.di.prog2.h18.refactored.ListBasedAbstractIntSet
elements
Fields inherited from class it.unimi.di.prog2.h18.refactored.AbstractIntSet
size
-
Constructor Summary
Constructors -
Method Summary
Methods inherited from class it.unimi.di.prog2.h18.refactored.ListBasedAbstractIntSet
iterator, remove
Methods inherited from class it.unimi.di.prog2.h18.refactored.AbstractIntSet
choose, equals, hashCode, size, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
OrderedIntSet
public OrderedIntSet()Creates an empty set.
-
-
Method Details
-
max
Returns the maximum element of this set.- Returns:
- the maximum element of this set.
- Throws:
NoSuchElementException
- if this set is empty.
-
min
Returns the minimum element of this set.- Returns:
- the maximum element of this set.
- Throws:
NoSuchElementException
- if this set is empty.
-
isIn
public boolean isIn(int x) Description copied from class:AbstractIntSet
Tells if the given element is in this set.Answers the question \( x\in S \).
- Overrides:
isIn
in classAbstractIntSet
- Parameters:
x
- the element to look for.- Returns:
- whether the given element belongs to this set, or not.
-
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 classAbstractIntSet
- Parameters:
x
- the element to be added.
-