From 0dc80b3b47363933eda4dfb7c179b23e7c6d6390 Mon Sep 17 00:00:00 2001 From: student Date: Wed, 1 Apr 2026 12:28:34 +0200 Subject: [PATCH] LinkedList und Knoten erstellt und 1 Fehlermelung bei loeschenAnPos(); --- .project | 11 +++++++++++ PR2pvl/.gitignore | 1 + PR2pvl/src/Knoten.java | 31 +++++++++++++++++++++++++++++++ PR2pvl/src/LinkedList.java | 24 ++++++++++++++++++++++++ 4 files changed, 67 insertions(+) create mode 100644 .project create mode 100644 PR2pvl/.gitignore create mode 100644 PR2pvl/src/Knoten.java create mode 100644 PR2pvl/src/LinkedList.java diff --git a/.project b/.project new file mode 100644 index 0000000..3284409 --- /dev/null +++ b/.project @@ -0,0 +1,11 @@ + + + PR2-Hummel-3024753 + + + + + + + + diff --git a/PR2pvl/.gitignore b/PR2pvl/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/PR2pvl/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/PR2pvl/src/Knoten.java b/PR2pvl/src/Knoten.java new file mode 100644 index 0000000..e90c7ac --- /dev/null +++ b/PR2pvl/src/Knoten.java @@ -0,0 +1,31 @@ + +public class Knoten { + + private int wert; + private Knoten nachfolger; + + Knoten(int wert){ + this.wert = wert; + this.nachfolger=null; + } + + + public void einfuegenAmEnde(int wert) { + if(this.nachfolger != null) { + Knoten k = new Knoten(wert); + this.nachfolger=k; + } + } + + + + public void auslesenAnPos(int pos) { + if(pos >0 && this.nachfolger != null) { + nachfolger.auslesenAnPos(pos--); + }else { + System.out.println(this.wert); + } + + } + // End of Class +} diff --git a/PR2pvl/src/LinkedList.java b/PR2pvl/src/LinkedList.java new file mode 100644 index 0000000..59d2d8f --- /dev/null +++ b/PR2pvl/src/LinkedList.java @@ -0,0 +1,24 @@ + +public class LinkedList { + private Knoten kopf; + + LinkedList(int wert){ + kopf = new Knoten(wert); + } + + + public void einfuegenAmEnde(int wert) { + kopf.einfuegenAmEnde(wert); + } + + public void auslesenAnPos(int pos) throws Exception { + + kopf.auslesenAnPos(pos); + } + + public void loeschenAnPos(int pos) throws Exception { + kopf.loeschenAnPos(pos); + + } + +}