Iterators in recursive functions
I've been having some trouble in a function that apparently should work perfectly fine. The program is about dealing withgraphs, detecting and showing theEuler path and circuit of a given graph
The following function is a depth first search , for each vertex it searches in depth the adjacent vertexes and checks each edge connecting each pair of vertexes. An iterator is used for each vertex, allowing to cover the list of adjacencies, that are on linked-list
/* edge[ ] is an array of edges, and the boolean visited defines if that edge already belongs to the circuit or not
circuit[ ] is an array where the edges of the path are saved
*/
publicboolean Euler(int n,int pos,int numSteps){
int ind;
//this section verifies the last step of the Euler circuit
if (pos==numSteps-2 && typeEuler==EULER_CIRCUIT){
ind = findEdge(circuito[pos], circuit[pos+2]);
if(ind != NOT_FOUND){
circuit[pos+1]=edge[ind].name();
returntrue;
}else{
edge[ind].set_visited(false);
returnfalse;
}
}
else{
/* The error is here: when the recursive call returns false (which means that no unvisited edge was found) the iterator doesn't increase, not pointing to the next adjacent vertex to continue building the Euler Path. This happens to all the pending calls, ending the DFS*/
it = verts[n].vertAdj().iterator();
pos+=2;
while (it.hasNext()){
tempS =(String)it.next();
ind=findEdge(verts[n].name(), tempS);
if( (ind != NOT_FOUND) && (!tempS.equals(circuit[0]))){
edge[ind].set_visited(true);
circuit[pos] = tempS;
circuit[pos-1] = edge[ind].nome();
n = searchVert(circuito[pos]);
if(pos==numSteps)// Ends Euler Path
returntrue;
if(Euler(n,pos,numSteps))
returntrue;
else
edge[ind].set_visited(false);
}
}
returnfalse;
}
}

