LinkedList und Knoten erstellt und 1 Fehlermelung bei loeschenAnPos();

main
student 2026-04-01 12:28:34 +02:00
parent c349e21796
commit 0dc80b3b47
4 changed files with 67 additions and 0 deletions

11
.project 100644
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>PR2-Hummel-3024753</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>

1
PR2pvl/.gitignore vendored 100644
View File

@ -0,0 +1 @@
/bin/

View File

@ -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
}

View File

@ -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);
}
}