From 309150a25fd49423656be7330e09612c0dbf6d0d Mon Sep 17 00:00:00 2001 From: hertero Date: Tue, 30 Aug 2022 10:21:02 +0200 Subject: [PATCH] add-Methode implementiert --- .../src/solution/SimpleLinkedList.java | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/SimpleLinkedList/src/solution/SimpleLinkedList.java b/SimpleLinkedList/src/solution/SimpleLinkedList.java index 60814fc..16cc611 100644 --- a/SimpleLinkedList/src/solution/SimpleLinkedList.java +++ b/SimpleLinkedList/src/solution/SimpleLinkedList.java @@ -24,19 +24,17 @@ public class SimpleLinkedList extends AbstractSimpleList { if (e == null) { return false; } else { - Node neuerKnoten = new Node<>(e); - - if (ersteKnoten == null) { - ersteKnoten = neuerKnoten; - } - else { - Node aktuellerKnoten = ersteKnoten; - while(aktuellerKnoten != null) { - aktuellerKnoten = aktuellerKnoten.getSuccessor(); + Node newNode = new Node<>(e); + + if (firstNode == null) { + firstNode = newNode; + } else { + Node currentNode = firstNode; + while (currentNode != null) { + currentNode = currentNode.getSuccessor(); } - aktuellerKnoten.setSuccessor(neuerKnoten); - aktuellerKnoten.setPredecessor(aktuellerKnoten); - + currentNode.setSuccessor(newNode); + currentNode.setPredecessor(currentNode); } } size++;