Java Array Permute permute(int k, Object[] os)

Here you can find the source of permute(int k, Object[] os)

Description

permute

License

Open Source License

Declaration

public static Object[] permute(int k, Object[] os) 

Method Source Code

//package com.java2s;
/**/*from   w w  w  . j  a  v  a2  s.  co  m*/
 * Copyright (C) 2009 G?nter Ladwig (gla at aifb.uni-karlsruhe.de)
 * 
 * This file is part of the graphindex project.
 *
 * graphindex is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License, version 2
 * as published by the Free Software Foundation.
 * 
 * graphindex is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with graphindex.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    public static Object[] permute(int k, Object[] os) {
        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;
    }
}

Related

  1. permutation(final int start, final int end)
  2. permutation(int n)
  3. permute(int[] elements, int i, int j)
  4. permute(int[] in, int[] idx)
  5. permute(int[] p, Object[] data, boolean clone)
  6. permute(String str, int startIndex, int endIndex)