数组全排列

数组全排列,不考虑重复值

public class AllPermutation {
    public static void doPermute(Character[] array) {
        doPermute(array, 0);
    }

    public static void doPermute(Character[] array, int start) {
        if (start == array.length - 1) {
            Utils.print(array);
            return;
        }

        int label = start;
        while (label <= array.length - 1) {
            Utils.swap(array, start, label);
            doPermute(array.clone(), start + 1);
            label++;
        }
    }

    public static void main(String[] args) {
        Character[] array = { 'a', 'b', 'c', 'd' };
        AllPermutation.doPermute(array);
    }
}

猜你喜欢

转载自dugu108.iteye.com/blog/1772090
今日推荐