Class ListIntSet
java.lang.Object
it.unimi.di.prog2.h17.AbstractIntSet
it.unimi.di.prog2.h17.ListIntSet
ListIntSets are mutable, unbounded sets of integers.
A typical ListIntSet is \( S = \{x_1, \ldots, x_n \} \).
-
Field Summary
FieldsFields inherited from class AbstractIntSet
size -
Constructor Summary
Constructors -
Method Summary
Methods inherited from interface Iterable
forEach, spliterator
-
Field Details
-
els
-
-
Constructor Details
-
ListIntSet
public ListIntSet()Initializes this set to be empty.Builds the set \( S = \varnothing \).
-
-
Method Details
-
getIndex
private int getIndex(int x) Looks for a given element in this set.- Parameters:
x- the element to look for.- Returns:
- the index where
xappears inelsif the element belongs to this set, or -1
-
insert
public void insert(int x) Adds the given element to this set.This method modifies the object, that is: \( S' = S \cup \{ x \} \).
- Specified by:
insertin classAbstractIntSet- Parameters:
x- the element to be added.
-
remove
public void remove(int x) Removes the given element from this set.This method modifies the object, that is: \( S' = S \setminus \{ x \} \).
- Specified by:
removein classAbstractIntSet- Parameters:
x- the element to be removed.
-
choose
Returns an element from this set.- Overrides:
choosein classAbstractIntSet- Returns:
- an arbitrary element from this set.
- Throws:
NoSuchElementException- if this set is empty.
-
iterator
-