Browse Source

add-Methode implementiert

vollständige_und_weitere_testate
hertero 3 years ago
committed by chris
parent
commit
309150a25f
  1. 22
      SimpleLinkedList/src/solution/SimpleLinkedList.java

22
SimpleLinkedList/src/solution/SimpleLinkedList.java

@ -24,19 +24,17 @@ public class SimpleLinkedList<E> extends AbstractSimpleList<E> {
if (e == null) {
return false;
} else {
Node<E> neuerKnoten = new Node<>(e);
if (ersteKnoten == null) {
ersteKnoten = neuerKnoten;
}
else {
Node<E> aktuellerKnoten = ersteKnoten;
while(aktuellerKnoten != null) {
aktuellerKnoten = aktuellerKnoten.getSuccessor();
Node<E> newNode = new Node<>(e);
if (firstNode == null) {
firstNode = newNode;
} else {
Node<E> currentNode = firstNode;
while (currentNode != null) {
currentNode = currentNode.getSuccessor();
}
aktuellerKnoten.setSuccessor(neuerKnoten);
aktuellerKnoten.setPredecessor(aktuellerKnoten);
currentNode.setSuccessor(newNode);
currentNode.setPredecessor(currentNode);
}
}
size++;

Loading…
Cancel
Save