continuata implementazione di graph. bfs dfs kruskal dijkstra
This commit is contained in:
39
graph/ComponentsBFS.java
Normal file
39
graph/ComponentsBFS.java
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user