From 5048b93887ef2dc3b9a9d9ee8c8de02d8caa60cc Mon Sep 17 00:00:00 2001 From: hertero Date: Tue, 30 Aug 2022 10:21:27 +0200 Subject: [PATCH] remove-Methode implementiert --- .../src/solution/SimpleLinkedList.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/SimpleLinkedList/src/solution/SimpleLinkedList.java b/SimpleLinkedList/src/solution/SimpleLinkedList.java index 16cc611..892f356 100644 --- a/SimpleLinkedList/src/solution/SimpleLinkedList.java +++ b/SimpleLinkedList/src/solution/SimpleLinkedList.java @@ -43,19 +43,19 @@ public class SimpleLinkedList extends AbstractSimpleList { @Override public boolean remove(Object o) { - if(o == null) { + if (o == null) { return false; } - Node aktuellerKnoten = ersteKnoten; - while(aktuellerKnoten != null) { - aktuellerKnoten = aktuellerKnoten.getSuccessor(); + Node currentNode = firstNode; + while (currentNode != null) { + currentNode = currentNode.getSuccessor(); } - if(o.equals(aktuellerKnoten)) { - aktuellerKnoten.setPayload(null); + if (o.equals(currentNode)) { + currentNode.setPayload(null); size--; - aktuellerKnoten = aktuellerKnoten.getPredecessor(); + currentNode = currentNode.getPredecessor(); return true; - + } return false; }