continuata implementazione di graph. bfs dfs kruskal dijkstra

This commit is contained in:
2014-05-28 00:52:03 +02:00
parent 395cf8a6e1
commit d6f43a646f
9 changed files with 566 additions and 0 deletions

39
graph/ComponentsBFS.java Normal file
View File

@@ -0,0 +1,39 @@
//gioel
package graph;
import java.security.InvalidKeyException;
public class ComponentsBFS<V, E> extends BFS<V, E, Object, Integer> {
protected Integer compNumber;
protected Object COMPONENT = new Object();
protected void setup() {
compNumber = 1;
}
protected void startVisit(Vertex<V> v) {
try {
v.put(COMPONENT, compNumber);
}
catch (InvalidKeyException e){
}
}
protected Integer finalResult(Integer bfsResult) {
try {
for(Vertex<V> v : graph.vertices())
if(!isVisited(v)) {
compNumber++;
bfsTraversal(v);
}
return compNumber;
}
catch (InvalidKeyException e){
}
return null;
}
}