DFS迭代功能无法正常工作

时间:2017-05-11 22:46:35

标签: java graph dfs

我正在尝试在图形上做一些基本功能(使用布尔矩阵)。除了DFS之外,它们都有效。它给了我一些随机数。我试图解决这个问题,因为现在几个小时,但仍然没有..(代码编译,但它显示它的错误)。顺便说一句,DFS的结果必须是一个矩阵,包含堆栈数,以及每个图顶点的“展开”。

我的错误在哪里?

我的节目:

    public int[][] DFS(int s) {

    Stack<Integer> stack = new Stack<Integer>();
    stack.push(s);
    int recorder = 1;
    int[][] mark = new int[nbs][2];

    mark[s][0] = recorder++;

    boolean[] decouvert = new boolean[nbs];
    while (!stack.isEmpty()) {
        s = stack.pop();
        mark[s][1] = recorder++;
        if (!decouvert[s]) {
            decouvert[s] = true;
            for (int i = 0; i < nbs; i++) {
                if (m[s][i]) {
                    stack.push(i);
                    mark[s][0] = recorder++;
                }
            }
        }
    }

    return mark;
}

0 个答案:

没有答案
相关问题