diff --git a/Aufteilung.txt b/Uebung04/Aufteilung.txt similarity index 100% rename from Aufteilung.txt rename to Uebung04/Aufteilung.txt diff --git a/CheckSparseVector.html b/Uebung04/CheckSparseVector.html similarity index 100% rename from CheckSparseVector.html rename to Uebung04/CheckSparseVector.html diff --git a/CheckSparseVector.java b/Uebung04/CheckSparseVector.java similarity index 100% rename from CheckSparseVector.java rename to Uebung04/CheckSparseVector.java diff --git a/SparseVector.html b/Uebung04/SparseVector.html similarity index 100% rename from SparseVector.html rename to Uebung04/SparseVector.html diff --git a/SparseVector.java b/Uebung04/SparseVector.java similarity index 100% rename from SparseVector.java rename to Uebung04/SparseVector.java diff --git a/Suchalgorythmen.java b/Uebung04/Suchalgorythmen.java similarity index 100% rename from Suchalgorythmen.java rename to Uebung04/Suchalgorythmen.java diff --git a/allclasses-index.html b/Uebung04/allclasses-index.html similarity index 100% rename from allclasses-index.html rename to Uebung04/allclasses-index.html diff --git a/allpackages-index.html b/Uebung04/allpackages-index.html similarity index 100% rename from allpackages-index.html rename to Uebung04/allpackages-index.html diff --git a/blatt04.pdf b/Uebung04/blatt04.pdf similarity index 100% rename from blatt04.pdf rename to Uebung04/blatt04.pdf diff --git a/copy.svg b/Uebung04/copy.svg similarity index 100% rename from copy.svg rename to Uebung04/copy.svg diff --git a/element-list b/Uebung04/element-list similarity index 100% rename from element-list rename to Uebung04/element-list diff --git a/help-doc.html b/Uebung04/help-doc.html similarity index 100% rename from help-doc.html rename to Uebung04/help-doc.html diff --git a/index-files/index-1.html b/Uebung04/index-files/index-1.html similarity index 100% rename from index-files/index-1.html rename to Uebung04/index-files/index-1.html diff --git a/index-files/index-2.html b/Uebung04/index-files/index-2.html similarity index 100% rename from index-files/index-2.html rename to Uebung04/index-files/index-2.html diff --git a/index-files/index-3.html b/Uebung04/index-files/index-3.html similarity index 100% rename from index-files/index-3.html rename to Uebung04/index-files/index-3.html diff --git a/index-files/index-4.html b/Uebung04/index-files/index-4.html similarity index 100% rename from index-files/index-4.html rename to Uebung04/index-files/index-4.html diff --git a/index-files/index-5.html b/Uebung04/index-files/index-5.html similarity index 100% rename from index-files/index-5.html rename to Uebung04/index-files/index-5.html diff --git a/index-files/index-6.html b/Uebung04/index-files/index-6.html similarity index 100% rename from index-files/index-6.html rename to Uebung04/index-files/index-6.html diff --git a/index-files/index-7.html b/Uebung04/index-files/index-7.html similarity index 100% rename from index-files/index-7.html rename to Uebung04/index-files/index-7.html diff --git a/index.html b/Uebung04/index.html similarity index 100% rename from index.html rename to Uebung04/index.html diff --git a/jquery-ui.overrides.css b/Uebung04/jquery-ui.overrides.css similarity index 100% rename from jquery-ui.overrides.css rename to Uebung04/jquery-ui.overrides.css diff --git a/legal/ADDITIONAL_LICENSE_INFO b/Uebung04/legal/ADDITIONAL_LICENSE_INFO similarity index 100% rename from legal/ADDITIONAL_LICENSE_INFO rename to Uebung04/legal/ADDITIONAL_LICENSE_INFO diff --git a/legal/ASSEMBLY_EXCEPTION b/Uebung04/legal/ASSEMBLY_EXCEPTION similarity index 100% rename from legal/ASSEMBLY_EXCEPTION rename to Uebung04/legal/ASSEMBLY_EXCEPTION diff --git a/legal/LICENSE b/Uebung04/legal/LICENSE similarity index 100% rename from legal/LICENSE rename to Uebung04/legal/LICENSE diff --git a/legal/jquery.md b/Uebung04/legal/jquery.md similarity index 100% rename from legal/jquery.md rename to Uebung04/legal/jquery.md diff --git a/legal/jqueryUI.md b/Uebung04/legal/jqueryUI.md similarity index 100% rename from legal/jqueryUI.md rename to Uebung04/legal/jqueryUI.md diff --git a/member-search-index.js b/Uebung04/member-search-index.js similarity index 100% rename from member-search-index.js rename to Uebung04/member-search-index.js diff --git a/module-search-index.js b/Uebung04/module-search-index.js similarity index 100% rename from module-search-index.js rename to Uebung04/module-search-index.js diff --git a/overview-tree.html b/Uebung04/overview-tree.html similarity index 100% rename from overview-tree.html rename to Uebung04/overview-tree.html diff --git a/package-search-index.js b/Uebung04/package-search-index.js similarity index 100% rename from package-search-index.js rename to Uebung04/package-search-index.js diff --git a/package-summary.html b/Uebung04/package-summary.html similarity index 100% rename from package-summary.html rename to Uebung04/package-summary.html diff --git a/package-tree.html b/Uebung04/package-tree.html similarity index 100% rename from package-tree.html rename to Uebung04/package-tree.html diff --git a/readme.txt b/Uebung04/readme.txt similarity index 100% rename from readme.txt rename to Uebung04/readme.txt diff --git a/resources/glass.png b/Uebung04/resources/glass.png similarity index 100% rename from resources/glass.png rename to Uebung04/resources/glass.png diff --git a/resources/x.png b/Uebung04/resources/x.png similarity index 100% rename from resources/x.png rename to Uebung04/resources/x.png diff --git a/script-dir/jquery-3.6.0.min.js b/Uebung04/script-dir/jquery-3.6.0.min.js similarity index 100% rename from script-dir/jquery-3.6.0.min.js rename to Uebung04/script-dir/jquery-3.6.0.min.js diff --git a/script-dir/jquery-ui.min.css b/Uebung04/script-dir/jquery-ui.min.css similarity index 100% rename from script-dir/jquery-ui.min.css rename to Uebung04/script-dir/jquery-ui.min.css diff --git a/script-dir/jquery-ui.min.js b/Uebung04/script-dir/jquery-ui.min.js similarity index 100% rename from script-dir/jquery-ui.min.js rename to Uebung04/script-dir/jquery-ui.min.js diff --git a/script.js b/Uebung04/script.js similarity index 100% rename from script.js rename to Uebung04/script.js diff --git a/search-page.js b/Uebung04/search-page.js similarity index 100% rename from search-page.js rename to Uebung04/search-page.js diff --git a/search.html b/Uebung04/search.html similarity index 100% rename from search.html rename to Uebung04/search.html diff --git a/search.js b/Uebung04/search.js similarity index 100% rename from search.js rename to Uebung04/search.js diff --git a/stylesheet.css b/Uebung04/stylesheet.css similarity index 100% rename from stylesheet.css rename to Uebung04/stylesheet.css diff --git a/tag-search-index.js b/Uebung04/tag-search-index.js similarity index 100% rename from tag-search-index.js rename to Uebung04/tag-search-index.js diff --git a/type-search-index.js b/Uebung04/type-search-index.js similarity index 100% rename from type-search-index.js rename to Uebung04/type-search-index.js diff --git a/Uebung08/Beispieldatei.txt b/Uebung08/Beispieldatei.txt new file mode 100644 index 0000000..005201b --- /dev/null +++ b/Uebung08/Beispieldatei.txt @@ -0,0 +1,34 @@ +// Red Black Tree Example + +digraph G { + graph [ratio=.48]; + node [style=filled, color=black, shape=circle, width=.6 + fontname=Helvetica, fontweight=bold, fontcolor=white, + fontsize=24, fixedsize=true]; + {rank = same; n1; 6; n4; n5; n6; n7; 22; 27}; + + 6, 8, 17, 22, 27 + [fillcolor=red]; + + n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11 + [label="NIL", shape=record, width=.4,height=.25, fontsize=16]; + + 13 -> 8, 17; + 8 -> 1 [weight=6]; + 8 -> 11 [weight=5]; + 17 -> 15 [weight=4]; + 17 -> 25 [weight=5]; + 1 -> n1 [weight=7]; + 1 -> 6; + 11 -> n4 [weight=10]; + 11 -> n5 [weight=14]; + 6 -> n2, n3; + 15 -> n6 [weight=14]; + 15 -> n7 [weight=10]; + 25 -> 22; + 25 -> 27 [weight=6]; + 22 -> n8 [weight=5]; + 22 -> n9 [weight=3]; + 27 -> n10 [weight=3]; + 27 -> n11 [weight=5]; +} \ No newline at end of file diff --git a/Uebung08/Main.java b/Uebung08/Main.java new file mode 100644 index 0000000..e53ad14 --- /dev/null +++ b/Uebung08/Main.java @@ -0,0 +1,169 @@ +public class Main { + + public static void main(String[] args) { + + // (ausgelagert) + // erstellen des this.Vektors = control Vector + RBTree controlVector = new RBTree(10); + controlVector.setElement(0, 10.0); + controlVector.setElement(5, 123.213); + controlVector.setElement(8, 65.01); + controlVector.setElement(9, 112.79); + controlVector.setElement(10, -212.79); + System.out.println("\n"); + + // erstellen der testVektoren (the 5 "others") + RBTree otherVector1 = new RBTree(10); + otherVector1.setElement(0, 10.0); + otherVector1.setElement(5, 123.213); + otherVector1.setElement(8, 65.01); + otherVector1.setElement(9, 112.79); + otherVector1.setElement(10, -212.79); + otherVector1.setElement(12, 12); + System.out.println("\n"); + + RBTree otherVector2 = new RBTree(5); + otherVector2.setElement(0, 0); + otherVector2.setElement(1, 2); + otherVector2.setElement(2, 5); + otherVector2.setElement(3, 11.0); + otherVector2.setElement(4, 22.2); + System.out.println("\n"); + + RBTree otherVector3 = new RBTree(20); + otherVector3.setElement(0, 123); + otherVector3.setElement(5, 11); + otherVector3.setElement(6, 20); + otherVector3.setElement(7, 7); + otherVector3.setElement(11, 2); + otherVector3.setElement(14, 3); + otherVector3.setElement(18, 4); + System.out.println("\n"); + + RBTree otherVector4 = new RBTree(10); // ein leerer other. Vektor mit Länge 10 + System.out.println("der Wert des otherVector4 an der Position 0 ist: " + otherVector4.getElement(0)); // 0.0 + System.out.println("der Wert des otherVector4 an der Position 5 ist: " + otherVector4.getElement(5)); // 0.0 + System.out.println("der Wert des otherVector4 an der Position 7 ist: " + otherVector4.getElement(7));// 0.0 + System.out.println("der Wert des otherVector4 an der Position 9 ist: " + otherVector4.getElement(9));// 0.0 + System.out.println("die Länge des otherVector4 ist: " + otherVector4.getLength()); // 10 + try { + System.out.println(otherVector4.getElement(99)); + } catch (Exception e) { + System.out.println(e); + } + try { + System.out.println(otherVector4.getElement(-1)); + } catch (Exception e) { + System.out.println(e); + } + System.out.println("\n"); + + RBTree otherVector5 = new RBTree(20); // ein leerer other. Vektor mit Länge 20 + System.out.println("der Wert des otherVector5 an der Position 0 ist: " + otherVector5.getElement(0)); // 0.0 + System.out.println("der Wert des otherVector5 an der Position 5 ist: " + otherVector5.getElement(5)); // 0.0 + System.out.println("der Wert des otherVector5 an der Position 17 ist: " + otherVector5.getElement(17));// 0.0 + System.out.println("der Wert des otherVector5 an der Position 19 ist: " + otherVector5.getElement(19));// 0.0 + System.out.println("die Länge des otherVector5 ist: " + otherVector5.getLength()); // 20 + try { + System.out.println(otherVector5.getElement(20)); + } catch (Exception e) { + System.out.println(e); + } + try { + System.out.println(otherVector5.getElement(-1)); + } catch (Exception e) { + System.out.println(e); + } + System.out.println("\n"); + + // Testen des this. Vektors --> testen Methoden wie getLength(), getElement(), + // setElement(), removeElement() + System.out.println("die Länge des controlVector ist: " + controlVector.getLength()); // 10 + System.out.println("der Wert des controlVector an der Position 5 ist: " + controlVector.getElement(5)); // 123.213 + System.out.println("der Wert des controlVector an der Position 0 ist: " + controlVector.getElement(0)); // 10.0 + System.out.println("der Wert des controlVector an der Position 1 ist: " + controlVector.getElement(1)); // 0.0 + try { + System.out.println(controlVector.getElement(99)); + } catch (Exception e) { + System.out.println(e); + } + try { + System.out.println(controlVector.getElement(-1)); + } catch (Exception e) { + System.out.println(e); + } + System.out.println("\n"); + + // testen equal(), wenn die beiden Vektoren identisch sind → should be true, not anymore :) + System.out.println(controlVector.equals(otherVector1)); + System.out.println("\n"); + + // Testen: Remove Element + controlVector.removeElement(5); + System.out.println("der Wert des controlVector an der Position 5 ist: " + controlVector.getElement(5)); // 0.0 + System.out.println("Die Länge nach remove ist: " + controlVector.getLength()); // 10 + System.out.println("\n"); + + controlVector.removeElement(7); + System.out.println("der Wert des controlVector an der Position 7 ist: " + controlVector.getElement(7)); // 0.0 + System.out.println("\n"); + + controlVector.setElement(5, 100); + System.out.println("der Wert des controlVector an der Position 5 ist: " + controlVector.getElement(5)); // 100.0 + System.out.println("\n"); + + // testen equals(other) --> nicht identisch + System.out.println(controlVector.equals(otherVector1)); // should be false, weil der Wert an Index 5 zu 100 gesetzt wurde + System.out.println(controlVector.equals(otherVector2)); // should be false + System.out.println(controlVector.equals(otherVector3)); // should be false + System.out.println(controlVector.equals(otherVector4)); // should be false + System.out.println("\n"); + + otherVector1.setElement(5, 100); + System.out.println("der Wert des otherVector1 an der Position 5 ist: " + otherVector1.getElement(5)); // 100.0 + System.out.println(otherVector1.equals(controlVector));// should be true, weil der Wert an Index 5 von this und other Vektor gleich 100 + System.out.println("\n"); + + // testen add() + controlVector.add(otherVector1); + + System.out.println("die Länge des controlVector ist: " + controlVector.getLength()); // 10 + System.out.println("der Wert des controlVector an der Position 0 ist: " + controlVector.getElement(0)); // 10 + 10 = 20 + System.out.println("der Wert des controlVector an der Position 5 ist: " + controlVector.getElement(5)); // 100 + 100 = 200 + System.out.println("der Wert des controlVector an der Position 6 ist: " + controlVector.getElement(6)); // 0.0 + System.out.println("der Wert des controlVector an der Position 8 ist: " + controlVector.getElement(8)); // 65.01 + 65.01 = 130.02 + System.out.println("der Wert des controlVector an der Position 9 ist: " + controlVector.getElement(9)); // 112.79 + 112.79 = 225.58 + System.out.println("\n"); + + controlVector.add(otherVector2); + + controlVector.setElement(3, 90.1); + System.out.println("der Wert des controlVector an der Position 0 ist: " + controlVector.getElement(0)); // 20 + System.out.println("der Wert des controlVector an der Position 3 ist: " + controlVector.getElement(3)); // 90.1 + System.out.println("\n"); + + controlVector.add(otherVector3); + System.out.println("der Wert des controlVector an der Position 0 ist: " + controlVector.getElement(0)); // 20 + System.out.println("der Wert des controlVector an der Position 5 ist: " + controlVector.getElement(5)); // 200 + System.out.println("der Wert des controlVector an der Position 9 ist: " + controlVector.getElement(9)); // 225.58 + System.out.println("\n"); + + controlVector.add(otherVector4); + + System.out.println("der Wert des controlVector an der Position 0 ist: " + controlVector.getElement(0)); + System.out.println("der Wert des controlVector an der Position 5 ist: " + controlVector.getElement(5)); + System.out.println("\n"); + + controlVector.removeElement(0); + + System.out.println("der Wert des controlVector an der Position 0 ist: " + controlVector.getElement(0)); // 0.0 + System.out.println("der Wert des controlVector an der Position 5 ist: " + controlVector.getElement(5)); // 200 + System.out.println("\n"); + + controlVector.add(otherVector5); + System.out.println("der Wert des controlVector an der Position 0 ist: " + controlVector.getElement(0)); // 0.0 + System.out.println("der Wert des controlVector an der Position 5 ist: " + controlVector.getElement(5)); // 200 + System.out.println("\n"); + + } +} diff --git a/Uebung08/RBTree.java b/Uebung08/RBTree.java new file mode 100644 index 0000000..d134017 --- /dev/null +++ b/Uebung08/RBTree.java @@ -0,0 +1,267 @@ +/** + * Sparse Implementierung einer verkettete Liste + */ +public class RBTree { + + /** + * Hilfsklasse, welche ein einzelnes Node repräsentiert. + * + * @author Paul + */ + private class Node { + int index; + double value; + Node next; + + public Node(int index, double value, Node next) { + this.index = index; + this.value = value; + this.next = next; + } + + } + + // Standard Konstruktor mit einem leeren Vektor initialisieren + private Node firstNode = null; + private int length = 0; + + /** + * Konstruktor mit Vektor länge 0 + * + * @author Elif + */ + public RBTree() { + this.firstNode = null; + this.length = 0; + } + + /** + * Konstruktor mit Vektor länge n + * + * @author Elif + * @param n Vektor länge + */ + public RBTree(int n) { + this.firstNode = null; + this.length = n; + } + + /** + * den value in index hinzufügen + * - Aktualisieren des Wertes, wenn der firstNode an dem Index mit einem Wert + * exisitiert + * - Neuer firstNode mit neuem Wert hinzufügen, wenn der firstNode an dem Index + * nicht existiert + * + * @author Elif + * @param index Stelle,w wo Vektor eingefügt werden soll + * @param value wert, den wir übergeben + */ + public void setElement(int index, double value) { + // methode wird aufgerufen, falls index existiert = platz schaffen + removeElement(index); + + int maxIndex = this.getLength() - 1; + // 1. if: schauen, ob Index im erlaubten Bereich + // 2. if: schauen, ob erster Knoten null ist und index von erstem knoten größer + // als index, dann neuen knoten setzen + if (index > maxIndex) { + System.out.println("Fehler: Der Index " + index + " ist außerhalb des erlaubten Bereichs."); + return; + } + + if (this.firstNode == null || this.firstNode.index > index) { + this.firstNode = new Node(index, value, this.firstNode); + + } + // hilfsknoten erstellen + // solange im index und gesuchten index nicht erreicht haben, gehen wir weiter + Node now = this.firstNode; + + while (now.next != null && now.next.index < index) { + now = now.next; + } + + // gesuchte index gefunden + if (now != null && now.index == index) { + now.value = value; + System.out.println("at index " + index + " set value " + value); + // knoten den wir erstellen wollten existiert nicht, deshlab new node + } else if (now.next == null || now.next.index > index) { + now.next = new Node(index, value, now.next); + System.out.println("at index " + index + " set value " + value); + + } + + } + + /** + * return the Wert value of that index input das Index, und return den + * entsprechenden Wert des Index + * + * @author Paul + * @param index Stelle, an der der Wert steht + * @return double Wert des Elements + */ + public double getElement(int index) { + + if (index < 0 || index >= this.length) { // für Testfall wenn Länge < index + throw new IndexOutOfBoundsException("Index " + index + " ist außerhalb der Vektorlänge " + this.length + + ". Max. Index ist " + (this.length - 1)); + } + + Node now = this.firstNode; + + while (now != null) { + if (now.index == index) { + return now.value; + } + now = now.next; + } + + return 0.0; + } + + /** + * entfernt Element nach Index + * + * @author Leonhard + * @param index Stelle des zu entferneden Elements + */ + public void removeElement(int index) { + // Anlegen der jetzigen und vorherigen Node + Node now = this.firstNode; + Node pre = null; + + // Wenn der momentane Node nicht Null ist und der gesuchte Index korrekt ist + // ersetze den momentanen Node durch den nächsten + if (now != null && now.index == index) { + this.firstNode = now.next; + return; + } + + // Während wir momentan nicht bei Null sind und den Index nicht gefunden haben + // setzte pre und now den nächsten Node weiter + while (now != null && now.index != index) { + pre = now; + now = now.next; + } + + // Wenn wir den Index gefunden haben und nicht bei Null sind + // setze den nächsten Node auf den momentanen Node + if (now != null && now.index == index) { + pre.next = now.next; + System.out.println("Node mit Wert: " + now.value + " am Index " + index + " gefunden und gelöscht."); + } else { + System.out.println("Keine Node am Index: " + index + " nicht gefunden!"); + } + } + + /** + * Gibt die Länge des Vektors aus + * + * @author Leonhard + * @return int Vektor Länge + */ + public int getLength() { + return RBTree.this.length; + } + + /** + * testen, ob other = this (nur vergleichen die Nicht-Null Elemente) + * + * @author YC Terry + * @param other Anderer Vektor, mit dem verglichen wird + * @return boolean Wahrheitswert, ob Vektoren gleich sind + */ + public boolean equals(RBTree other) { + + if (this.getLength() != other.getLength()) { + + return false; + + } + + Node thisnow = this.firstNode; + Node othernow = other.firstNode; + + while (thisnow != null || othernow != null) { + + if (thisnow != null && othernow != null) { + if (!(thisnow.index == othernow.index && thisnow.value == othernow.value)) { + return false; + } + + thisnow = thisnow.next; + othernow = othernow.next; + + // wenn die Anzahl der Positionen mit Nicht-Null-Elementen nicht übereinstimmen + // = nicht identisch + } else if ((thisnow != null && othernow == null) || (othernow != null && thisnow == null)) { + + return false; + } + + } + return true; + } + + /** + * to add two vectors together and renew (overwrite) the this.vector + * + * @author YC Terry + * @param other Anderer Vektor, der auf addiert wird + */ + public void add(RBTree other) { + + Node thisnow = this.firstNode; + Node othernow = other.firstNode; + Node thispre = null; + + // Fall 0: 2 Vektoren mit unterschiedlichen Längen geht nicht! + if (this.getLength() != other.getLength()) { + + System.out.println("Vektoren mit unterschiedlichen Längen können nicht zusammen addiert werden!!"); + System.out.println( + "Länge des controlVector: " + this.getLength() + " aber die von otherVector: " + other.getLength()); + return; + + } + + while (thisnow != null && othernow != null) { + + // Fall 1, gleicher Index, dann nur Werte zusammen addieren → update this Vektor + if (thisnow.index == othernow.index) { + thisnow.value += othernow.value; // overwrite the this. value + thispre = thisnow; + thisnow = thisnow.next; + othernow = othernow.next; + } + + // Fall 2: Der Index von othernow ist kleiner, füge diesen Knoten in this ein + else if (othernow.index < thisnow.index) { + + Node newNode = new Node(othernow.index, othernow.value, thisnow); + + if (thispre == null) { + this.firstNode = newNode; + } else { + thispre.next = newNode; + } + + // this Vektor Zeiger und other Vektor Zeiger gehen weiter voran + othernow = othernow.next; + thispre = newNode; + + // Fall 3: Der Index von othernow > thisnow, 2 Zeiger gehen weiter + } else if (othernow.index > thisnow.index) { + + thispre = thisnow; + thisnow = thisnow.next; + + } + + } + + } +} \ No newline at end of file diff --git a/Uebung08/blatt08.pdf b/Uebung08/blatt08.pdf new file mode 100644 index 0000000..be58245 Binary files /dev/null and b/Uebung08/blatt08.pdf differ