public class PermutationIterator extends Object implements Iterator<Permutation>
hasNext() method is O(1).
The runtime of the next() method is O(n), as it does O(n) swaps in the worst-case, and regardless of number
of swaps it returns a copy (an O(n) operation) of the internally maintained Permutation object so the caller can safely
modify the returned Permutation without risk of interfering with the operation of the Iterator.| Constructor and Description |
|---|
PermutationIterator(int n)
Initializes a PermutationIterator to iterate over all permutations of a given length.
|
PermutationIterator(Permutation p)
Initializes a PermutationIterator to iterate over all permutations the same length as a given permutation.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
hasNext() |
Permutation |
next() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforEachRemaining, removepublic PermutationIterator(int n)
n - The length of the permutations.public PermutationIterator(Permutation p)
p - The first permutation in the iteration.public boolean hasNext()
hasNext in interface Iterator<Permutation>public Permutation next()
next in interface Iterator<Permutation>Copyright © 2005-2020 Vincent A. Cicirello. All rights reserved.