I'm trying to make a program for find all the Euler Paths in a graph. For doing this, I'm using a code adapted from this: http://www.sanfoundry.com/java-program-implement-euler-circuit-problem/
What I do: I modified a recursive function printEulerUtil() (below) for test and find (method isValidNextEdge) the possibles Euler paths. But, my recursive method doesn't stores the variable int[][] localAdjacencyMatrix (it's like a global variable, i can't understand that), which means that when the recursion returns (for example, after find the first Euler path in a deep first search), my variable is the same of the last recursive call (like I said, a global variable behaviour), not storing the values of the "original" call before in the program (the contexts before the first recursion call).
What I'm doing wrong? All the context is not saved when recursion occurs, after all?
Here is a piece of the code (commented):
// in the main call, variable vertex and localAdjacencyMatrix are defined in the constructor.
public void printEulerTourUtil(int vertex, int[][] localAdjacencyMatrix) {
ArrayList<Integer> destinationVertexes = new ArrayList<>();
int destination = 1;
// print the actual vertex
System.out.println("V: " + vertex);
for (destination = 1; destination <= numberOfNodes; destination++) {
// test all possibles destinations
if (localAdjacencyMatrix[vertex][destination] == 1 && isValidNextEdge(vertex, destination, localAdjacencyMatrix)) {
// insert these destinations in a list of next vertex for recursion
destinationVertexes.add(destination);
System.out.println(destination + " ");
}
}
// make a recursion for every vertex destination in the list.
for (int i = 0; i < destinationVertexes.size(); i++){
destination = destinationVertexes.get(i);
// go to the next vertex in the graph
System.out.println("-> source : " + vertex + " destination " + destination);
// localAdjacencyMatrix isn't working. it's like a global variable, so my recursion fails
removeEdge(vertex, destination, localAdjacencyMatrix);
printEulerTourUtil(destination, localAdjacencyMatrix);
}
Sorry any english mistake and any help will be very useful! Thank you!