C++로 구현한 부분집합 구하기
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
int Value[MAX_DEPTH];
 
void BinaryTree(int initDepth, int depth) {
    if(initDepth == depth) {
        printf("{");
        for(int i=0; i<=depth; i++)
            if(Value[depth-i] == 1) printf(" %d ", i);
        printf("}\n");
        return ;
    }
 
    Value[initDepth] = 0;
    BinaryTree(initDepth + 1, depth);
    Value[initDepth] = 1;
    BinaryTree(initDepth + 1, depth);
}



References