public final class IntCombinationsWithPermutations extends Object
k numbers, which can be chosen from the set of n numbers (0,1,2,...,n). The
total number of such combinations will be n!/(n-k)!.
For example, for k=2 and n=3, it will produce the following arrays sequence: [0,1], [1,0], [0,2],
[2,0], [1,2], [2,1].
The iterator is implemented such that each next combination will be calculated only on the invocation of method
next() (no pre-calculation of results).
Note: method next() returns the same reference on each invocation.
Internally this class uses combination of IntCombinations and IntPermutations.
IntCombinations,
IntPermutations,
Serialized Form| Constructor and Description |
|---|
IntCombinationsWithPermutations(int n,
int k)
Constructs the iterator with the desired n and k
|
| Modifier and Type | Method and Description |
|---|---|
int[] |
current()
Returns the reference on the current iteration element.
|
boolean |
hasNext() |
int[] |
next()
Calculates and returns the next combination.
|
void |
remove()
Throws UnsupportedOperationException.
|
void |
reset()
Resets the iteration
|
List<int[]> |
toList()
Write all elements of this iterable to list
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waititerator, streamforEachRemainingforEach, spliteratorpublic IntCombinationsWithPermutations(int n,
int k)
public boolean hasNext()
public int[] next()
public void remove()
public void reset()
CombinatorialIteratorpublic int[] current()
CombinatorialIteratorpublic final List<int[]> toList()
CombinatorialIteratortoList in interface CombinatorialIterator<int[]>Copyright © 2017. All rights reserved.