|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.paulhertz.util.Permutator
public class Permutator
Maintains an ArrayList
of Integer
initialized in ascending order, and
steps it to each successive permutation. The next permutation is the one
that would appear next in a sorted list of all permutations, where the sorting function
orders in ascending order. In the final permutation, each number is greater than the previous
and no more permutations are possible.
This class is particularly intended for permutation of the indices of arrays of objects.
TODO permutations of m objects taken n at a time.
Constructor Summary | |
---|---|
Permutator(int size)
|
Method Summary | |
---|---|
ArrayList<Integer> |
getPerm()
Returns the permutation array. |
ArrayList<Integer> |
getPermCopy()
Returns a copy of the permutation array: call this if you feel the urge to modify the array. |
int |
getSize()
|
void |
initPerm()
Initializes the permutation array to integer values from 0 to size - 1. |
static String |
listToString(ArrayList<Integer> permArray)
Converts elements in the supplied permutation to a string. |
static String |
listToString(int[] permArray)
Converts elements in the supplied permutation to a string. |
boolean |
nextPerm()
Steps to next permutation of the permutation array, returns false if the last permutation has been reached. |
static boolean |
nextPerm(ArrayList<Integer> permArray)
Steps to next permutation of an ArrayList of Integer ,
returns false if the last permutation has been reached. |
static boolean |
nextPerm(int[] permArray)
Steps to next permutation of an array of integers, returns false if the last permutation has been reached. |
void |
setPerm(ArrayList<Integer> perm)
Set the permutation array to the supplied ArrayList of Integer . |
String |
toString()
|
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Permutator(int size)
Method Detail |
---|
public void initPerm()
public ArrayList<Integer> getPerm()
getPermCopy
.
public void setPerm(ArrayList<Integer> perm)
ArrayList
of Integer
.
perm
- an ArrayList
of Integer
to setpublic ArrayList<Integer> getPermCopy()
ArrayList
of Integer
, copy of the permutation arraypublic int getSize()
public boolean nextPerm()
public String toString()
toString
in class Object
public static boolean nextPerm(ArrayList<Integer> permArray)
ArrayList
of Integer
,
returns false if the last permutation has been reached. The next permutation is the one
that would appear next in a sorted list of all permutations, where the sorting function
orders in ascending order. In the final permutation, each number is greater than the previous
and no more permutations are possible. This is an implementation of an algorithm described by
Edsger Dijkstra in "A Discipline of Programming" [Prentice-Hall, 1976].
public static boolean nextPerm(int[] permArray)
public static String listToString(ArrayList<Integer> permArray)
permArray
- an ArrayList
of Integer
public static String listToString(int[] permArray)
permArray
- an ArrayList
of Integer
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |