metodo boobleano para saber si hay camino directo grafos

Technology

metodo boobleano para saber si hay camino directo grafos


public boolean hayCaminoDirecto(Vertice origen,
Vertice destino) {
if (vertices.size() > 1) {
if (origen != null && destino != null) {
for (Arista a : origen.getAristas()) {
if (a.getDestino().equals(destino)) {
return true;
}
}
}
return false;
}
return false;
}
public int caminoDirectoCorto(Vertice origen, Vertice
destino) {
if (vertices.size() > 1) {
int p1 = 0, p2 = 0;
if (origen != null && destino != null) {
for (Arista a : origen.getAristas()) {
if (a.getDestino().equals(destino)) {
p1 = (Integer) a.getPeso();
if (p2 == 0) {
p2 = p1;
}
if (p1 < p2) {
p2 = p1;
}
}
return p2;
}
}
return 0;
}
return 0;
}

Post a Comment

0 Comments