Android Array Permutate identityPermutation(final int[] a)

Here you can find the source of identityPermutation(final int[] a)

Description

Fills the given array with a[i] = i.

License

Open Source License

Parameter

Parameter Description
a an array

Declaration

public static void identityPermutation(final int[] a) 

Method Source Code

//package com.java2s;
/**//from ww w . j  a v a2 s  . com
 * jcombinatorics:
 * Java Combinatorics Library
 *
 * Copyright (c) 2009 by Alistair A. Israel.
 *
 * This software is made available under the terms of the MIT License.
 * See LICENSE.txt.
 *
 * Created Aug 31, 2009
 */

public class Main {
    /**
     * Fills the given array with a[i] = i. For example, if a = int[4], then
     * fills <code>a</code> with <code>{ 0, 1, 2, 3 }</code>. Used throughout
     * permutation and combination generation as the first result
     * (lexicographically).
     * 
     * @param a
     *            an array
     */
    public static void identityPermutation(final int[] a) {
        for (int i = a.length - 1; i >= 0; --i) {
            a[i] = i;
        }
    }

    /**
     * Creates and fills an array with a[i] = i. For example, if n = 4, then
     * returns <code>{ 0, 1, 2, 3 }</code>. Used throughout permutation and
     * combination generation as the first result (lexicographically).
     * 
     * @param n
     *            the size of the array
     * @return the initialized array
     */
    public static int[] identityPermutation(final int n) {
        final int[] a = new int[n];
        identityPermutation(a);
        return a;
    }
}

Related

  1. identityPermutation(final int n)