anhang:graphadj:start
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Beide Seiten der vorigen RevisionVorhergehende ÜberarbeitungNächste Überarbeitung | Vorhergehende Überarbeitung | ||
anhang:graphadj:start [2024/11/29 10:21] – Martin Pabst | anhang:graphadj:start [2024/12/06 07:17] (aktuell) – Martin Pabst | ||
---|---|---|---|
Zeile 58: | Zeile 58: | ||
public void setKante(String knoten1, String knoten2, int gewicht12, int gewicht21) | public void setKante(String knoten1, String knoten2, int gewicht12, int gewicht21) | ||
</ | </ | ||
+ | [[.loesung1: | ||
</ | </ | ||
- | < | ||
- | <div class=" | ||
- | |||
- | <script type=" | ||
- | public class Graph { | ||
- | // | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | // | ||
- | |||
- | // | ||
- | | ||
- | this.maxAnzahl = maxAnzahl; | ||
- | anzahl = 0; | ||
- | knotenliste = new Knoten[maxAnzahl]; | ||
- | adjazenzmatrix = new int [maxAnzahl][maxAnzahl]; | ||
- | |||
- | } | ||
- | |||
- | | ||
- | return anzahl; | ||
- | } | ||
- | |||
- | | ||
- | int index = getNächsterFreierKnotenIndex(); | ||
- | knotenliste[index] = k; | ||
- | anzahl++; | ||
- | } | ||
- | |||
- | | ||
- | for (int i = 0; i < maxAnzahl; i++) { | ||
- | | ||
- | } | ||
- | | ||
- | throw new RuntimeException(" | ||
- | |||
- | return -1; // Hier kommt das Programm nie hin. | ||
- | } | ||
- | |||
- | | ||
- | return knotenliste[index]; | ||
- | } | ||
- | |||
- | | ||
- | for (int i = 0; i < maxAnzahl; i++) { | ||
- | | ||
- | if(k != null) { | ||
- | println(k.toString()); | ||
- | } | ||
- | } | ||
- | } | ||
- | |||
- | | ||
- | knotenliste[index] = null; | ||
- | for (int i = 0; i < maxAnzahl; i++) { | ||
- | | ||
- | | ||
- | } | ||
- | } | ||
- | |||
- | | ||
- | adjazenzmatrix[index1][index2] = gewicht12; | ||
- | adjazenzmatrix[index2][index1] = gewicht21; | ||
- | } | ||
- | |||
- | | ||
- | setKante(index1, | ||
- | } | ||
- | |||
- | | ||
- | for (int i = 0; i < maxAnzahl; i++) { | ||
- | | ||
- | if(k != null && k.getInhalt().getName() == name) { | ||
- | return i; | ||
- | } | ||
- | } | ||
- | return -1; | ||
- | } | ||
- | |||
- | | ||
- | int index1 = knotenIndexSuchen(knoten1); | ||
- | int index2 = knotenIndexSuchen(knoten2); | ||
- | | ||
- | if(index1 == -1 && index2 == -1) return; | ||
- | |||
- | setKante(index1, | ||
- | |||
- | } | ||
- | |||
- | | ||
- | setKante(knoten1, | ||
- | } | ||
- | |||
- | |||
- | } | ||
- | </ | ||
- | <script type=" | ||
- | public class Knoten { | ||
- | | ||
- | |||
- | // | ||
- | | ||
- | inhalt = d; | ||
- | } | ||
- | |||
- | // | ||
- | | ||
- | return inhalt; | ||
- | } | ||
- | |||
- | //set - Methode | ||
- | | ||
- | inhalt = d; | ||
- | } | ||
- | |||
- | | ||
- | return inhalt.getName(); | ||
- | } | ||
- | } | ||
- | </ | ||
- | <script type=" | ||
- | class Datenelement { | ||
- | | ||
- | |||
- | | ||
- | this.name = name; | ||
- | } | ||
- | |||
- | | ||
- | return name; | ||
- | } | ||
- | |||
- | | ||
- | this.name = name; | ||
- | } | ||
- | } | ||
- | </ | ||
- | <script type=" | ||
- | @Test | ||
- | class MyFirstTestClass { | ||
- | |||
- | Graph getExampleGraph() { | ||
- | Graph g = new Graph(10); | ||
- | Knoten k1 = new Knoten(new Datenelement(" | ||
- | Knoten k2 = new Knoten(new Datenelement(" | ||
- | Knoten k3 = new Knoten(new Datenelement(" | ||
- | g.knotenEinfuegen(k1); | ||
- | g.knotenEinfuegen(k2); | ||
- | g.knotenEinfuegen(k3); | ||
- | return g; | ||
- | } | ||
- | |||
- | @Test | ||
- | void testGetAnzahl() { | ||
- | Graph g = getExampleGraph(); | ||
- | assertEquals(3, | ||
- | } | ||
- | |||
- | |||
- | @Test | ||
- | void testKnotenLoeschen() { | ||
- | Graph g = getExampleGraph(); | ||
- | g.knotenLoeschen(2); | ||
- | assertEquals(2, | ||
- | } | ||
- | } | ||
- | </ | ||
- | </ | ||
- | </ | ||
anhang/graphadj/start.1732875692.txt.gz · Zuletzt geändert: 2024/11/29 10:21 von Martin Pabst