Modificato alcune classi

This commit is contained in:
2014-06-01 20:32:07 +02:00
parent 71cea16bcb
commit 01c626d0e0
6 changed files with 36 additions and 54 deletions

View File

@@ -1,35 +1,21 @@
package graph;
//begin#fragment CC
import exceptions.InvalidKeyException;
/** This class extends DFS to compute the connected components of a graph. */
public class ComponentsDFS<V, E> extends DFS<V, E, Object, Integer> {
protected Integer compNumber; // Connected component number
protected Object COMPONENT = new Object(); // Connected comp. selector
protected void setup() { compNumber = 1; }
protected void startVisit(Vertex<V> v) {
try{
v.put(COMPONENT, compNumber);
}
catch (InvalidKeyException e){
//
}
}
protected Integer finalResult(Integer dfsResult) {
try{
for (Vertex<V> v : graph.vertices()) // check for any unvisited vertices
if (v.get(STATUS) == UNVISITED) {
compNumber += 1; // we have found another connected component
dfsTraversal(v); // visit all the vertices of this component
}
return compNumber;
}
catch (InvalidKeyException e){
//
}
return null;
}
}
//end#fragment CC