@@ -0,0 +1,39 @@ | |||
package adt; | |||
public class List { | |||
public Node first; | |||
public void hinzufügen(Schüler s) { | |||
Node neu = new Node(s, null); | |||
Node zwischen = first; | |||
// Wenn Liste noch leer | |||
if(first == null) { | |||
first = neu; | |||
} else { // ansonsten | |||
while(zwischen.next != null) { | |||
// gehe durch die Liste bis zum Ende | |||
zwischen = zwischen.next; | |||
} | |||
// an letztes Element anhängen | |||
zwischen.next = neu; | |||
} | |||
} | |||
public int länge() { | |||
if(first == null) { | |||
return 0; | |||
} | |||
Node zwischen = first; | |||
int count = 0; | |||
while(zwischen != null) { | |||
count++; | |||
zwischen = zwischen.next; | |||
} | |||
return count; | |||
} | |||
} |
@@ -0,0 +1,11 @@ | |||
package adt; | |||
public class Node { | |||
public Schüler s; | |||
public Node next; | |||
public Node(Schüler s, Node next) { | |||
this.s = s; | |||
this.next = next; | |||
} | |||
} |
@@ -0,0 +1,11 @@ | |||
package adt; | |||
public class Schüler { | |||
public String Name; | |||
public String Klasse; | |||
public Schüler(String Name, String Klasse) { | |||
this.Name = Name; | |||
this.Klasse = Klasse; | |||
} | |||
} |
@@ -0,0 +1,23 @@ | |||
package adt; | |||
public class Start { | |||
public static void main(String[] args) { | |||
List l = new List(); | |||
l.hinzufügen( new Schüler("Max Haeffele", "AMG 11") ); | |||
l.hinzufügen( new Schüler("Emil Amboni", "DHG 11") ); | |||
l.hinzufügen( new Schüler("Anastasia Hermann", "DHG 11") ); | |||
System.out.println("Es stehen " + l.länge() + " Schüler in der Schlange"); | |||
// Sekretärin | |||
Node sekretärin = l.first; | |||
while(sekretärin != null) { | |||
System.out.println(sekretärin.s.Name); | |||
sekretärin = sekretärin.next; | |||
} | |||
} | |||
} |