Modificato alcune classi
This commit is contained in:
@@ -38,34 +38,33 @@ public class DFS<V, E, I, R> {
|
||||
if (!isDone())
|
||||
startVisit(v);
|
||||
if (!isDone()) {
|
||||
visit(v);
|
||||
for (Edge<E> e: graph.incidentEdges(v)) {
|
||||
if (!isVisited(e)) {
|
||||
// found an unexplored edge, explore it
|
||||
visit(e);
|
||||
Vertex<V> w = graph.opposite(v, e);
|
||||
if (!isVisited(w)) {
|
||||
// w is unexplored, this is a discovery edge
|
||||
traverseDiscovery(e, v);
|
||||
if (isDone()) break;
|
||||
visitResult = dfsTraversal(w); // get result from DFS-tree child
|
||||
if (isDone()) break;
|
||||
}
|
||||
else {
|
||||
// w is explored, this is a back edge
|
||||
traverseBack(e, v);
|
||||
if (isDone()) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
visit(v);
|
||||
for (Edge<E> e: graph.incidentEdges(v)) {
|
||||
if (!isVisited(e)) {
|
||||
// found an unexplored edge, explore it
|
||||
visit(e);
|
||||
Vertex<V> w = graph.opposite(v, e);
|
||||
if (!isVisited(w)) {
|
||||
// w is unexplored, this is a discovery edge
|
||||
traverseDiscovery(e, v);
|
||||
if (isDone()) break;
|
||||
visitResult = dfsTraversal(w); // get result from DFS-tree child
|
||||
if (isDone()) break;
|
||||
} else {
|
||||
// w is explored, this is a back edge
|
||||
traverseBack(e, v);
|
||||
if (isDone()) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!isDone())
|
||||
finishVisit(v);
|
||||
return result();
|
||||
}
|
||||
//end#fragment DFS2
|
||||
|
||||
//begin#fragment decorations
|
||||
|
||||
|
||||
/** Mark a position (vertex or edge) as visited. */
|
||||
protected void visit(DecorablePosition<?> p) throws InvalidKeyException{
|
||||
p.put(STATUS, VISITED);
|
||||
@@ -100,7 +99,5 @@ public class DFS<V, E, I, R> {
|
||||
protected R result() { return null; /* default value */ }
|
||||
/** Returns the final result of the DFS execute method. */
|
||||
protected R finalResult(R r) { return r; /* default value */ }
|
||||
//end#fragment auxiliary
|
||||
//begin#fragment Tail
|
||||
} // end of DFS class
|
||||
//end#fragment Tail
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user