package graph; import java.util.Objects; import java.util.Vector; public class UndirectedGraph extends Graph { // KONSTRUKTOREN public UndirectedGraph() { super(); } public UndirectedGraph(String s) { super(s); } // Ausgabe public String toString() { return ""; } // KNOTEN EIGENSCHAFTEN // Prüfung des Grades eines Knotens public int degree(MarkedVertex n) { int degree = 0; for (MarkedEdge i: this.getAllEdges()) { if (i.getSource() == n) { degree += 1; } if (i.getDestination() == n) { degree += 1; } } return degree; } public int degree(String s) throws NameDoesNotExistException{ for (MarkedVertex i: this.getAllVertexes()) { if (Objects.equals(i.getName(), s)) { return degree(i); } } throw new NameDoesNotExistException("One of the Vertexes might not exist"); } // Prüfung, welche Knoten Nachbarn sind public Vector> getNeighbours(MarkedVertex n) { Vector> neighbours = new Vector<>(); for (MarkedEdge i: this.getAllEdges()) { if (i.getSource() == n && !neighbours.contains(i.getDestination())) { neighbours.add(i.getDestination()); } else if (i.getDestination() == n && !neighbours.contains(i.getSource())) { neighbours.add(i.getSource()); } } return neighbours; } }