metodo saber si hay vertices con bucles grafos

Technology

metodo saber si hay vertices con bucles grafos


public LinkedList verticeConBucles() {
LinkedList lista = new LinkedList();
if (vertices.size() > 0) {
for (Vertice v : vertices) {
verticeConBucles(v, lista);
}
}
return null;
}
private void verticeConBucles(Vertice v, LinkedList
lista) {
if (v.getAristas().size() > 0) {
for (Arista a : v.getAristas()) {
if (a.getDestino().equals(v)) {
if (!lista.contains(a.getDestino())) {
lista.add(a.getDestino()); }}}}}
public int cuantosBucles(Vertice v) {
if (vertices.size() > 0) {
int x = 0;
for (Arista a : v.getAristas()) {
if (a.getDestino().equals(v)) {
x += 1;
}}
return x;
}
return 0;
}
public int cuantosBuclesGrafo() {
if (vertices.size() > 0) {
int x = 0;
for (Vertice v : vertices) {
for (Arista a : v.getAristas()) {
if (a.getDestino().equals(v)) {
x += 1;
}}
}
return x;
}
return 0;
}

Post a Comment

0 Comments