포스팅 목차
public class CM_순열조합 {
public static void main(String[] args) {
int[] a = new int[]{1,2,3,4};
soon(a, 0, 3, 3);
System.out.println();
johab(new int[3], 0, 4, 3, 0);
}
public static void soon(int[] data, int index, int totalDataCnt, int choiceDataCnt){
int temp;
if(index == choiceDataCnt){
int[] dd = new int[choiceDataCnt];
for(int i=0; i< dd.length; i++){
dd[i] = data[i];
}
System.out.println(Arrays.toString(dd));
}
else{
for(int i=index; i<totalDataCnt; i++){
temp = data[index];
data[index] = data[i];
data[i] = temp;
soon(data, index+1, totalDataCnt, choiceDataCnt);
temp = data[index];
data[index] = data[i];
data[i] = temp;
}
}
}
public static void johab(int[] data, int index, int totalDataCnt, int choiceDataCnt, int target){
if(choiceDataCnt == 0){
System.out.println(Arrays.toString(data));
}
else if(totalDataCnt == target){
return;
}
else{
data[index] = target;
johab(data, index+1, totalDataCnt, choiceDataCnt-1, target+1);
johab(data, index, totalDataCnt, choiceDataCnt, target+1);
}
}
}
[1, 2, 3]
[1, 3, 2]
[2, 1, 3]
[2, 3, 1]
[3, 2, 1]
[3, 1, 2]
[0, 1, 2]
[0, 1, 3]
[0, 2, 3]
[1, 2, 3]