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
All Implemented Interfaces:
Iterator<List<T>>

public class CombinationsIterator<T> extends Object implements Iterator<List<T>>
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 Details

    • CombinationsIterator

      public CombinationsIterator(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.
      Parameters:
      elements - given list of elements
      combinationSize - size of the combinations of elements
      See Also:
  • Method Details