From dfbc01fc9b3af05b59bba8510f113ac8fb01a6dd Mon Sep 17 00:00:00 2001 From: davifd <@> Date: Fri, 13 Jan 2023 12:56:12 +0100 Subject: [PATCH] Ubgrade 13.1.2023 --- LinkedList.java | 3 ++ LinkedList2.java | 71 ++++++++++++++++++++++++++++++++++++++++++++++++ List.java | 25 +++++++++++++++++ test.java | 24 ++++++++++++++++ 4 files changed, 123 insertions(+) create mode 100644 LinkedList2.java create mode 100644 List.java diff --git a/LinkedList.java b/LinkedList.java index ab7afe9..64c31d8 100644 --- a/LinkedList.java +++ b/LinkedList.java @@ -67,7 +67,9 @@ public class LinkedList Node neu = new Node(wert); if(n==0){ + //setze Nachfolger auf bisherigen Stand neu.setNext(first); + //setze neuen Start auf neuen first = neu; }else{ Node current = first; @@ -80,4 +82,5 @@ public class LinkedList } } + } \ No newline at end of file diff --git a/LinkedList2.java b/LinkedList2.java new file mode 100644 index 0000000..dd6a496 --- /dev/null +++ b/LinkedList2.java @@ -0,0 +1,71 @@ + +/** + * Beschreiben Sie hier die Klasse List. + * + * @author (Ihr Name) + * @version (eine Versionsnummer oder ein Datum) + */ +public class LinkedList2 +{ + public List first; + + public LinkedList2(){} + public void einfuegen (T neu) { + List n = new List(neu);//Neue Node mit Zahl "neu " anlegen + + //Überprüfe ob die liste leer ist + if(first == null){ + //setze neue node als erster Eintrag + first = n; + } + else { + List current = first; + + while(current.next != null){ + current = current.next; + } + current.setNext(n); + } + + //current ist jetzt der letzte Eintrag + //setze neue Node als Nachfolger von bisher letztem Eintrag + } + public boolean isEmpty(){ + if (first == null){ + return true; + } + return false; + } + + public int laenge(){ + List current = first; + int laenge = 0; + while(current != null){ + current = current.next; + laenge++; + } + return laenge; + } + + + public T getNteZahl(int n){ + List current = first; + for(int i = 0; i current = first; + + //gehe an den Vorgänger des zu löschenden Eintrags + for(int i=0; i +{ + +public T zahl; + +public List next; + +public List(T g){ +zahl = g; +} +public void setNext(List h){ +next = h; + + +} + +} + diff --git a/test.java b/test.java index 5823dbe..8bb41ba 100644 --- a/test.java +++ b/test.java @@ -32,5 +32,29 @@ public class test } + public static void test2(){ + List test = new List("Hallo"); + List test2 = new List(5); + + LinkedList2 liste = new LinkedList2(); + liste.einfuegen(5); + liste.einfuegen(6); + liste.einfuegen(8); + liste.einfuegen(3); + liste.einfuegen(7); + liste.einfuegen(9); + liste.loesche(2); + + List current = liste.first; + + while(current != null){ + System.out.println( current.zahl ); + current = current.next; + } + + System.out.println("Die Liste hat "+liste.laenge()+" Einträge. "); + + +} }