diff --git a/sources/src/main/java/pr2/generics/einfach/Liste.java b/sources/src/main/java/pr2/generics/einfach/Liste.java index b4be384..86b395d 100644 --- a/sources/src/main/java/pr2/generics/einfach/Liste.java +++ b/sources/src/main/java/pr2/generics/einfach/Liste.java @@ -8,7 +8,7 @@ package pr2.generics.einfach; /** * Eine einfache, verkettete Liste. */ -public class Liste { +public class Liste { /** Referenz auf den ersten Knoten. */ private ListeNode first; @@ -31,7 +31,7 @@ public class Liste { current = nextNode; } else { - current.next = nextNode; + current.setNext(nextNode); current = nextNode; } } @@ -47,7 +47,7 @@ public class Liste { ListeNode node = first; while ((node != null) && (count < index)) { - node = node.next; + node = node.getNext(); count++; } @@ -78,7 +78,7 @@ public class Liste { ListeNode node = first; while (node != null) { - node = node.next; + node = node.getNext(); count++; } diff --git a/sources/src/main/java/pr2/generics/einfach/ListeNode.java b/sources/src/main/java/pr2/generics/einfach/ListeNode.java index bb1d1ca..0336f11 100644 --- a/sources/src/main/java/pr2/generics/einfach/ListeNode.java +++ b/sources/src/main/java/pr2/generics/einfach/ListeNode.java @@ -10,7 +10,6 @@ class ListeNode { /** Referenz auf den nächsten Knoten. */ ListeNode next; - /** * Legt einen neuen Knoten an. * @@ -19,4 +18,10 @@ class ListeNode { ListeNode(Object data) { this.data = data; } + public ListeNode getNext() { + return next; + } + public void setNext(ListeNode next) { + this.next = next; + } } diff --git a/sources/src/main/java/pr2/generics/einfach/test/ListeTest.java b/sources/src/main/java/pr2/generics/einfach/test/ListeTest.java index e680148..673d13b 100644 --- a/sources/src/main/java/pr2/generics/einfach/test/ListeTest.java +++ b/sources/src/main/java/pr2/generics/einfach/test/ListeTest.java @@ -22,7 +22,7 @@ public class ListeTest { l.add("Hallo"); assertEquals(1, l.size()); - l.add("Hugo"); + l.add(34); assertEquals(2, l.size()); l.add("Peter"); l.add("Alfons");