Datentypen
parent
d843998f71
commit
2588954185
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
</attributes>
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=17
|
||||
org.eclipse.jdt.core.compiler.compliance=11
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
|
@ -11,4 +11,4 @@ org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
|||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||
org.eclipse.jdt.core.compiler.release=enabled
|
||||
org.eclipse.jdt.core.compiler.source=17
|
||||
org.eclipse.jdt.core.compiler.source=11
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
public class LinkedList<A> {
|
||||
|
||||
private Node<A> start; // Attribut start mit Node mit Genertic als Datentyp
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
|
||||
public class Set<P> {
|
||||
private Node<P> start;
|
||||
private int size;
|
||||
|
||||
|
||||
public Set() {
|
||||
this.start = null;
|
||||
this.size = 0;
|
||||
}
|
||||
public boolean isEmpty() { // Klasse fragt ab ob die liste leer ist
|
||||
if (size == 0) { // wenn l‰nge der liste 0 ist
|
||||
|
||||
return true; // gibt true zur¸ck weil es boolean ist
|
||||
} else { // wenn oberes nicht erfÔøΩllt wird
|
||||
|
||||
return false; // gibt false zur¸ck wegen boolean
|
||||
}
|
||||
}
|
||||
public void add(P wert) { // Methode f‰ngt hinten an die Liste etwas an
|
||||
this.size++; // grˆfle wird hochgez‰hlt da liste um ein grˆfler werden muss
|
||||
if(contains(wert) == false) {
|
||||
if (this.start == null) { // wenn start wert = 0 ist
|
||||
this.start = new Node<P>(wert); // start wird zu neuem Knoten mit wert wert
|
||||
} else { // wenn obere if bedingung nicht erf¸llt wird dann soll er volgendes ausgef¸hrt
|
||||
Node<P> current = this.start; // current bekommt den wert der start zugewissen wurde
|
||||
while (current.next != null) { // w‰hrend nachfolger des jetzigen Knotens ungleich null ist
|
||||
current = current.next; // wird current dem n‰chsten werd zugewissen
|
||||
|
||||
}
|
||||
current.next = new Node<P>(wert); // dem jetzigen Knoten wird als 2ter eintrag ein neuer Knoten zugewissen
|
||||
}
|
||||
} else {return;}
|
||||
}
|
||||
|
||||
public boolean contains(P wert) { //gibt aus ob ein wert in der Liste ist
|
||||
Node<P> current = this.start; // Knoten current wird der wert start zugewissen
|
||||
while (current != null) { // solange current ungleich null ist wird das in der Schleife ausgefÔøΩhrt
|
||||
|
||||
if (current.wert == wert) { // wenn der der Knoten current = der wert ist
|
||||
System.out.println(wert + " " + "ist nicht der Liste");
|
||||
return true; // dann gibt es den eintrag also muss er true zurÔøΩckgeben
|
||||
}
|
||||
current = current.next; // n‰chster wert wird zum aktuellen
|
||||
|
||||
}
|
||||
System.out.println(wert + " " + "ist in der Liste");
|
||||
return false; // sonst ist er nicht drin
|
||||
}
|
||||
public void remove(P wert) {
|
||||
Node<P> current = this.start; // neuer Knoten current wird erstellt
|
||||
if(current.wert == wert) {
|
||||
this.start = current.next;
|
||||
}
|
||||
while(current.next != null) {
|
||||
if(current.next.wert == wert) {
|
||||
current.next = current.next.next;
|
||||
size--;
|
||||
}
|
||||
current = current.next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
|
||||
public class SetTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Set<Integer> set = new Set<Integer>();
|
||||
set.add(3);
|
||||
set.add(2);
|
||||
set.add(4);
|
||||
set.add(4);
|
||||
set.remove(2);
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue