Browse Source

Leo: Ordner für Übung 08 angelegt

master
fdai7303 4 months ago
parent
commit
a59a110e53
  1. 0
      Uebung04/Aufteilung.txt
  2. 0
      Uebung04/CheckSparseVector.html
  3. 0
      Uebung04/CheckSparseVector.java
  4. 0
      Uebung04/SparseVector.html
  5. 0
      Uebung04/SparseVector.java
  6. 0
      Uebung04/Suchalgorythmen.java
  7. 0
      Uebung04/allclasses-index.html
  8. 0
      Uebung04/allpackages-index.html
  9. 0
      Uebung04/blatt04.pdf
  10. 0
      Uebung04/copy.svg
  11. 0
      Uebung04/element-list
  12. 0
      Uebung04/help-doc.html
  13. 0
      Uebung04/index-files/index-1.html
  14. 0
      Uebung04/index-files/index-2.html
  15. 0
      Uebung04/index-files/index-3.html
  16. 0
      Uebung04/index-files/index-4.html
  17. 0
      Uebung04/index-files/index-5.html
  18. 0
      Uebung04/index-files/index-6.html
  19. 0
      Uebung04/index-files/index-7.html
  20. 0
      Uebung04/index.html
  21. 0
      Uebung04/jquery-ui.overrides.css
  22. 0
      Uebung04/legal/ADDITIONAL_LICENSE_INFO
  23. 0
      Uebung04/legal/ASSEMBLY_EXCEPTION
  24. 0
      Uebung04/legal/LICENSE
  25. 0
      Uebung04/legal/jquery.md
  26. 0
      Uebung04/legal/jqueryUI.md
  27. 0
      Uebung04/member-search-index.js
  28. 0
      Uebung04/module-search-index.js
  29. 0
      Uebung04/overview-tree.html
  30. 0
      Uebung04/package-search-index.js
  31. 0
      Uebung04/package-summary.html
  32. 0
      Uebung04/package-tree.html
  33. 0
      Uebung04/readme.txt
  34. 0
      Uebung04/resources/glass.png
  35. 0
      Uebung04/resources/x.png
  36. 0
      Uebung04/script-dir/jquery-3.6.0.min.js
  37. 0
      Uebung04/script-dir/jquery-ui.min.css
  38. 0
      Uebung04/script-dir/jquery-ui.min.js
  39. 0
      Uebung04/script.js
  40. 0
      Uebung04/search-page.js
  41. 0
      Uebung04/search.html
  42. 0
      Uebung04/search.js
  43. 0
      Uebung04/stylesheet.css
  44. 0
      Uebung04/tag-search-index.js
  45. 0
      Uebung04/type-search-index.js
  46. 34
      Uebung08/Beispieldatei.txt
  47. 169
      Uebung08/Main.java
  48. 267
      Uebung08/RBTree.java
  49. BIN
      Uebung08/blatt08.pdf

0
Aufteilung.txt → Uebung04/Aufteilung.txt

0
CheckSparseVector.html → Uebung04/CheckSparseVector.html

0
CheckSparseVector.java → Uebung04/CheckSparseVector.java

0
SparseVector.html → Uebung04/SparseVector.html

0
SparseVector.java → Uebung04/SparseVector.java

0
Suchalgorythmen.java → Uebung04/Suchalgorythmen.java

0
allclasses-index.html → Uebung04/allclasses-index.html

0
allpackages-index.html → Uebung04/allpackages-index.html

0
blatt04.pdf → Uebung04/blatt04.pdf

0
copy.svg → Uebung04/copy.svg

0
element-list → Uebung04/element-list

0
help-doc.html → Uebung04/help-doc.html

0
index-files/index-1.html → Uebung04/index-files/index-1.html

0
index-files/index-2.html → Uebung04/index-files/index-2.html

0
index-files/index-3.html → Uebung04/index-files/index-3.html

0
index-files/index-4.html → Uebung04/index-files/index-4.html

0
index-files/index-5.html → Uebung04/index-files/index-5.html

0
index-files/index-6.html → Uebung04/index-files/index-6.html

0
index-files/index-7.html → Uebung04/index-files/index-7.html

0
index.html → Uebung04/index.html

0
jquery-ui.overrides.css → Uebung04/jquery-ui.overrides.css

0
legal/ADDITIONAL_LICENSE_INFO → Uebung04/legal/ADDITIONAL_LICENSE_INFO

0
legal/ASSEMBLY_EXCEPTION → Uebung04/legal/ASSEMBLY_EXCEPTION

0
legal/LICENSE → Uebung04/legal/LICENSE

0
legal/jquery.md → Uebung04/legal/jquery.md

0
legal/jqueryUI.md → Uebung04/legal/jqueryUI.md

0
member-search-index.js → Uebung04/member-search-index.js

0
module-search-index.js → Uebung04/module-search-index.js

0
overview-tree.html → Uebung04/overview-tree.html

0
package-search-index.js → Uebung04/package-search-index.js

0
package-summary.html → Uebung04/package-summary.html

0
package-tree.html → Uebung04/package-tree.html

0
readme.txt → Uebung04/readme.txt

0
resources/glass.png → Uebung04/resources/glass.png

Before

Width: 16  |  Height: 16  |  Size: 499 B

After

Width: 16  |  Height: 16  |  Size: 499 B

0
resources/x.png → Uebung04/resources/x.png

Before

Width: 16  |  Height: 16  |  Size: 394 B

After

Width: 16  |  Height: 16  |  Size: 394 B

0
script-dir/jquery-3.6.0.min.js → Uebung04/script-dir/jquery-3.6.0.min.js

0
script-dir/jquery-ui.min.css → Uebung04/script-dir/jquery-ui.min.css

0
script-dir/jquery-ui.min.js → Uebung04/script-dir/jquery-ui.min.js

0
script.js → Uebung04/script.js

0
search-page.js → Uebung04/search-page.js

0
search.html → Uebung04/search.html

0
search.js → Uebung04/search.js

0
stylesheet.css → Uebung04/stylesheet.css

0
tag-search-index.js → Uebung04/tag-search-index.js

0
type-search-index.js → Uebung04/type-search-index.js

34
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];
}

169
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");
}
}

267
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;
}
}
}
}

BIN
Uebung08/blatt08.pdf

Loading…
Cancel
Save