用DFS来求一个集合的子集(!!TAT)

数组中存放10个数,为{0、1、2、3、4、5、6、7、8、9}
请输出它的子集
请用DFS算法来解答,请使用C
【小白被这道题困扰好几天了】

https://blog.csdn.net/kid_a1412/article/details/114156220

#include <stdio.h>
// 栈
typedef struct Node {
    // 是否已访问
    int visited;
    // 值
    int value;
} Node;
Node NullValue;
typedef struct stack{
    int length;
    Node arrs[10];
}s1;
s1 stack;

Node node[10];
int arrs[10] = { 0,1,2,3,4,5,6,7,8,9 };
int getLength() {
    return stack.length;
}
int getHead() {
    return stack.arrs[stack.length].value;
}
int push(Node a) {
    stack.arrs[stack.length++] = a;
}
void pop() {
    stack.arrs[stack.length--] = NullValue;
}
void display() {
    for (int i = 0; i < stack.length; i++) {
        printf("%d ", stack.arrs[i].value);
    }
    printf("\n");
}


int main() {
    int length;
    int j = 0;
    int index,now;
    int i;
    NullValue.value = -1;
    stack.length = 0;
    // 把数组当作 树
    //        0
    //     1    2
    //    3 4  5 6
    //  7 8 9
    
    for (i = 0; i < 10; i++) {
        node[i].value = arrs[i];
        node[i].visited = 0;
    }
    
    for (i = 0; i < 10; i++) {
        // 结果
        length = getLength();
        for (j = 0; j <length; j++) {
            pop();
        }
        index = i;
        now = i;
        push(node[i]);
        node[i].visited = 1;
        display();
        index++;
        while (getLength() != 10 - i) {
            if (index < 10) {
                if (node[index].visited == 0) {
                    push(node[index]);
                    node[index].visited = 1;
                    display();
                    pop();
                    index++;
                }
            }
            else {
                index = ++now;
                push(node[index]);
                index++;
                for (j = 0; j < 10; j++) {
                    node[j].visited = 0;
                }
            }
        }
        
    }
    
    
    return 0;
}
0
0 1
0 2
0 3
0 4
0 5
0 6
0 7
0 8
0 9
0 1 2
0 1 3
0 1 4
0 1 5
0 1 6
0 1 7
0 1 8
0 1 9
0 1 2 3
0 1 2 4
0 1 2 5
0 1 2 6
0 1 2 7
0 1 2 8
0 1 2 9
0 1 2 3 4
0 1 2 3 5
0 1 2 3 6
0 1 2 3 7
0 1 2 3 8
0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 9
5
5 6
5 7
5 8
5 9
5 6 7
5 6 8
5 6 9
5 6 7 8
5 6 7 9
5 6 7 8 9
6
6 7
6 8
6 9
6 7 8
6 7 9
6 7 8 9
7
7 8
7 9
7 8 9
8
8 9
9

课后作业:用递归函数描述这个方法如何实现的。

您好,您的问题已经有小伙伴解答了,如果有答案帮您提供解决思路,请点击【采纳】按钮,给回答的人一些鼓励哦~~

ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632