From a85f2525b41b6240277ae507dd2b346b60b7290b Mon Sep 17 00:00:00 2001 From: Khwanchanok Srimool Date: Sun, 20 May 2018 03:39:26 +0700 Subject: [PATCH] fix remove method --- DataStructures/Lists/CircleLinkedList.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/DataStructures/Lists/CircleLinkedList.java b/DataStructures/Lists/CircleLinkedList.java index d4bb2a0d2..0c1ce0f36 100644 --- a/DataStructures/Lists/CircleLinkedList.java +++ b/DataStructures/Lists/CircleLinkedList.java @@ -34,7 +34,7 @@ public class CircleLinkedList{ } public E remove(int pos){ - if(pos>size || pos< 0){ + if(pos>=size || pos< 0){ //catching errors throw new IndexOutOfBoundsException("position cannot be greater than size or negative"); } @@ -45,13 +45,15 @@ public class CircleLinkedList{ iterator = iterator.next; before = before.next; } - E saved = iterator.value; - // assigning the next referance to the the element following the element we want to remove... the last element will be assigned to the head. + E removedValue = iterator.value; + // assigning the next reference to the the element following the element we want to remove... the last element will be assigned to the head. before.next = iterator.next; // scrubbing iterator.next = null; iterator.value = null; + size--; - return saved; + return removedValue; } + } \ No newline at end of file