Class PermutationsIterator<T>
java.lang.Object
com.amalgamasimulation.core.combinatorics.PermutationsIterator<T>
- Type Parameters:
T
- the type of elements in the list
Iterator for generating all permutations of the provided list of elements.
The permutations are generated in a lazy manner, meaning they are created
on-the-fly as they are requested through the
next()
method. This
approach is memory efficient as it does not require storing all permutations
in memory at once.
Usage example:
This will print out all permutations of the list [1, 2, 3].List<Integer> numbers = Arrays.asList(1, 2, 3);
var iterator = new PermutationsIterator<>(numbers);
while (iterator.hasNext()) {List<Integer> permutation = iterator.next();
System.out.println(permutation); }
- Author:
- Alexander Morozov