forked from jainaman224/Algo_Ds_Notes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConnectionStructure.java
38 lines (29 loc) · 999 Bytes
/
ConnectionStructure.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package kruskal;
import java.util.HashMap;
import java.util.HashSet;
class ConnectionStructure {
private final HashSet<Integer> conectados;
private final HashMap<Integer, Vertice> conjunto;
public ConnectionStructure(HashMap<Integer, Vertice> conjunto) {
conectados = new HashSet<>();
this.conjunto = conjunto;
}
public void conecta(Integer v) {
conectados.add(v);
}
public boolean isCompletelyConnected() {
exploraGrafo(this.conjunto.entrySet().iterator().next().getValue());
return conectados.size() == conjunto.size();
}
private void exploraGrafo(Vertice v) {
if (!estaVerticeConectado(v.getId())) {
conecta(v.getId());
for (Vertice value : v.getDifferentWays().values()) {
exploraGrafo(value);
}
}
}
public boolean estaVerticeConectado(Integer v) {
return conectados.contains(v);
}
}