I'm trying to do some basic function on a graph (using a boolean matrix). They all work except the DFS one. It give me some random number. I'm trying to resolve this problem since few hours now, but still nothing.. (the code compile, but what it show its wrong). Btw, the result of DFS must be a matrix, with the number of stack, and also the "Unwinding" of each graph vertex.
Where's my error?
My program :
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;
}