java.lang.Iterable<int[]>public class Combinations
extends java.lang.Object
implements java.lang.Iterable<int[]>
| Modifier and Type | Class | Description |
|---|---|---|
static class |
Combinations.LexicographicComparator |
Defines a lexicographic ordering of the combinations.
|
| Constructor | Description |
|---|---|
Combinations(int n,
int k) |
Creates an instance whose range is the k-element subsets of
{0, ..., n - 1} represented as
int[] arrays. |
| Modifier and Type | Method | Description |
|---|---|---|
int |
getK() |
Gets the number of elements in each combination.
|
int |
getN() |
Gets the size of the set from which combinations are drawn.
|
java.util.Iterator<int[]> |
iterator() |
public Combinations(int n,
int k)
int[] arrays.
The iteration order is lexicographic: the arrays returned by the
iterator are sorted in descending order and
they are visited in lexicographic order with significance from
right to left.
For example, new Combinations(4, 2).iterator() returns
an iterator that will generate the following sequence of arrays
on successive calls to
next():
[0, 1], [0, 2], [1, 2], [0, 3], [1, 3], [2, 3]
k == 0 an iterator containing an empty array is returned;
if k == n an iterator containing [0, ..., n - 1] is returned.n - Size of the set from which subsets are selected.k - Size of the subsets to be enumerated.java.lang.IllegalArgumentException - if n < 0.java.lang.IllegalArgumentException - if k > n or k < 0.public int getN()
public int getK()
public java.util.Iterator<int[]> iterator()
iterator in interface java.lang.Iterable<int[]>Copyright © 2017 The Apache Software Foundation. All rights reserved.