All pastes #3693 Raw Edit

Anonymous

public text v1 · immutable
#3693 ·published 2005-01-03 13:11 UTC
rendered paste body
/* Permutationen von char[] */
public class permu {
    public static char[] liesZeichenfolge() {
        System.out.print("char[]: ");
        String s = "";
        try { 
            s = new java.io.BufferedReader(
                    new java.io.InputStreamReader(System.in)).readLine();
        }
        catch (java.io.IOException e) {}
        return s.toCharArray();
    }
    static char[] a,printMe;
    public static void perm() {
        java.util.Arrays.sort(a);
        printMe = new char[a.length];
        perm(0,0);
    }
    public static void perm(int pos, int done) {
        char pre = '\0';
        if(pos != a.length) {
            for(int x=0;x<a.length;x++)
                if(a[x] != pre && (done&(1<<x)) == 0) {
                    pre = a[x];
                    printMe[pos] = pre;
                    perm(pos+1,(done|(1<<x)));
                }
        }
        else 
            System.out.println(new String(printMe));
    }
    public static void main(String [] args) {
        a = liesZeichenfolge(); perm();
    }
}