Übung generische Liste

master
Kai Sellmann 2023-05-30 19:25:19 +02:00
parent 09a63d8d9c
commit 9bb4149c94
3 changed files with 11 additions and 6 deletions

View File

@ -8,7 +8,7 @@ package pr2.generics.einfach;
/**
* Eine einfache, verkettete Liste.
*/
public class Liste {
public class Liste<E> {
/** 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++;
}

View File

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

View File

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