Class PermutationsIterator<T>

java.lang.Object
com.amalgamasimulation.core.combinatorics.PermutationsIterator<T>
Type Parameters:
T - the type of elements in the list
All Implemented Interfaces:
Iterator<List<T>>

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

 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);
 }
 
This will print out all permutations of the list [1, 2, 3].

Author:
Alexander Morozov
  • Constructor Details

    • PermutationsIterator

      public PermutationsIterator(List<? extends T> elements)
  • Method Details