Click here to Skip to main content
15,889,651 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to figure out how to find all paths between to nodes through all edges, not vertices. Was thinking about visited[][], to check did edge was visited, but I came up with some problems. Maybe I there is simple way and I can't see it. Any ideas?

void allPathsDFS(int verticeFrom, int verticeTo, boolean[] visited, Deque<Integer> paths, List<List<Integer>> rezults){
    visited[verticeFrom] = true;
    paths.add(verticeFrom);
    if (verticeFrom == verticeTo){
        rezults.add(new ArrayList<Integer>(paths));
    }
    else{
        if(adj.containsKey(verticeFrom)){
            for(Integer i : adj.get(verticeFrom)){
                if(!visited[i] ){                                                        
                    allPathsDFS(i, verticeTo, visited, paths, rezults);
                }
            }
        }
    }
    paths.removeLast();
    visited[verticeFrom] = false;
}


What I have tried:

Visited Boolean[][] with pointing which edge was visited
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900