LinkedList und Knoten erstellt und 1 Fehlermelung bei loeschenAnPos();
parent
c349e21796
commit
0dc80b3b47
|
|
@ -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>
|
||||
|
|
@ -0,0 +1 @@
|
|||
/bin/
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue