W@n 0 Newbie Poster

Hi, recently i am doing an assignment that require me to do a depth first search on a given graph. However, i cannot get the result i needed. Is there any wrong with my code? Can anyone help? thank in advance=D

My graph

0                   4
  /   \                /
 1     2 ---3         5

The depth first search result should be 0,1,2,3 but i can only get 0,1.

my code

public static void depthFirstRecurse(int v) {

        //mark v as visit
        visited = new boolean[g.getGraphSize()];
        visited[v] = true;
        
        System.out.print(v + " ");

        for (int u = 1; u < g.getGraphSize(); u++) {

            if (visited[u] == false && adjMatrix[u][v] == 1) {
                
                             depthFirstRecurse(u);

            }
            return;
        }
        
    }