src/com/michaelho/GraphAlgorithms/GR1.java
/**
         * The function that is recursively used in DFS traversal.
         *
         * @param graph The input graph.
         * @param list The list that is used as output.
         * @param v The value of current vertex.
         * @param visited The boolean array that records whether the vertex is visited.
         * */
The function that is recursively used in DFS traversal.
@param graph The input graph.
@param list The list that is used as output.
@param v The value of current vertex.
@param visited The boolean array that records whether the vertex is visited.
The function that is recursively used in DFS traversal . @param graph The input graph . @param list The list that is used as output . @param v The value of current vertex . @param visited The boolean array that records whether the vertex is visited .
private void DFSHelper(Graph graph, List<Integer> list, int v, boolean[] visited) {
            visited[v] = true;
            list.add(v);
            List<Edge> adjList = graph.getAdjacencyList(v);
            for (int i = 0; i < adjList.size(); i++) {
                if (!visited[adjList.get(i).dest.val]) {
                    DFSHelper(graph, list, adjList.get(i).dest.val, visited);
                }
            }
        }
private void DFSHelper ( Graph graph , List < Integer > list , int v , boolean [ ] visited ) { visited [ v ] = true ; list . add ( v ) ; List < Edge > adjList = graph . getAdjacencyList ( v ) ; for ( int i = 0 ; i < adjList . size ( ) ; i ++ ) { if ( ! visited [ adjList . get ( i ) . dest . val ] ) { DFSHelper ( graph , list , adjList . get ( i ) . dest . val , visited ) ; } } }
The function that is recursively used in DFS traversal.
The function that is recursively used in DFS traversal .