Class CombinationsIterator<T>
java.lang.Object
com.amalgamasimulation.core.combinatorics.CombinationsIterator<T>
- Type Parameters:
T
- the type of elements in the input lists and the combinations produced by this iterator
An iterator over all possible combinations of a specified size from the given
list of elements. Each combination is a list of elements chosen from the
input list, without repetition and regardless of order. This class provides
an iterative approach to generating and traversing each combination, without
generating all combinations in memory upfront.
For example, if the input list is [1, 2, 3]
and
combinationSize
is 2, the result would include [1, 2]
,
[1, 3]
, and [2, 3]
.
The elements are generated in the lexicographical order
- Author:
- Andrey Malykhanov
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCombinationsIterator
(List<? extends T> elements, int combinationSize) Creates a new instance of an iterator over all possible combinations of a specified size from the given list of elements. -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Iterator
forEachRemaining, remove
-
Constructor Details
-
CombinationsIterator
Creates a new instance of an iterator over all possible combinations of a specified size from the given list of elements.- Parameters:
elements
- given list of elementscombinationSize
- size of the combinations of elements- See Also:
-
-
Method Details