The list of methods to do Array Permute are organized into topic(s).
int[]
permutation(final int start, final int end) Creates a permutation of all integers in the interval [start, end]
if (start > end)
return new int[0];
final int length = end - start + 1;
final int[] r = new int[length];
for (int i = 0; i < length; i++)
r[i] = start + i;
for (int i = length - 1; i > 0; i--) {
final int j = random.nextInt(i + 1);
...
int[]
permutation(int n) Generates a random permutation of the numbers {0, ..., n-1}
return permutation(n, getRandomGenerator());
Object[]
permute(int k, Object[] os) permute
for (int j = 2; j <= os.length; j++) {
k = k / (j - 1);
Object tmp = os[j - 1];
os[j - 1] = os[(k % j)];
os[(k % j)] = tmp;
return os;
int[]
permute(int[] in, int[] idx) permute
int[] out = new int[in.length];
for (int i = 0; i < in.length; i++)
out[i] = in[idx[i]];
return out;
Object[]
permute(int[] p, Object[] data, boolean clone) Rearrange the specified data according to the specified permutation.
Object[] permuted = null;
if (clone) {
permuted = (Object[]) data.clone();
for (int i = 0; i < data.length; i++)
permuted[p[i]] = data[i];
} else {
int i = 0;
while (i < p.length) {
...
void
permute(String str, int startIndex, int endIndex) Algo {A,B,C} first take index 0 and swap with all A swap with A {A,B,C} ---> now take second char and make first char fixed {A,B,C} and {A,C,B} A swap with B {B,A,C} ---> now take second char and make first char fixed {B,A,C} and {B,C,A} A swap with C {C,B,A} ---> now take second char and make first char fixed {C,B,A} and {C,A,B} now take second char on each
if (startIndex == endIndex) {
System.out.println(str);
} else {
for (int i = startIndex; i <= endIndex; i++) {
str = swap(str, startIndex, i);
permute(str, startIndex + 1, endIndex);
str = swap(str, startIndex, i);
void
permute(T[] array) Randomly permute the values in array .
Collections.shuffle(Arrays.asList(array));
T[]
permute(T[] values) "Randomly" permute an array in place.
for (int i = 0; i < values.length; i++) {
swap(values, i, generator.nextInt(values.length));
return values;