static int count = 0;
static char[] array = { 'a', 'b', 'c' };
static LinkedList<char[]> list = new LinkedList<char[]> ();
static int[] indexs = new int[3];
static int len = array.length;
public static void main(String[] args){
getSub ();
for ( char[] cs : list ){
System.out.println (Arrays.toString (cs));
}
}
private static LinkedList<char[]> getSub (){
while (count <= len){
recursionSub (0, -1);
count++;
}
return list;
}
private static LinkedList <char[]> recursionSub ( int ind, int start ){
start++;
if (start > count - 1){
return null;
}
for ( indexs[start] = 0; indexs[start] < len; indexs[start]++ ){
recursionSub (0, start);
if (start == count - 1){
char[] temp = new char[count];
for ( int i = count - 1; i >= 0; i-- ){
temp[start - i] = array[indexs[start - i]];
}
boolean flag = true;
for ( int i = 0; i < temp.length; i++ ){
for ( int j = i+1; j < temp.length; j++ ){
if (temp[i] == temp[j]){
flag = false;
break;
}
}
}
if (flag){
list.add (temp);
}
}
}
return list;
}
|