Skip to content

Commit a85f252

Browse files
committed
fix remove method
1 parent c4a8e1e commit a85f252

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

DataStructures/Lists/CircleLinkedList.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public void append(E value){
3434
}
3535

3636
public E remove(int pos){
37-
if(pos>size || pos< 0){
37+
if(pos>=size || pos< 0){
3838
//catching errors
3939
throw new IndexOutOfBoundsException("position cannot be greater than size or negative");
4040
}
@@ -45,13 +45,15 @@ public E remove(int pos){
4545
iterator = iterator.next;
4646
before = before.next;
4747
}
48-
E saved = iterator.value;
49-
// assigning the next referance to the the element following the element we want to remove... the last element will be assigned to the head.
48+
E removedValue = iterator.value;
49+
// assigning the next reference to the the element following the element we want to remove... the last element will be assigned to the head.
5050
before.next = iterator.next;
5151
// scrubbing
5252
iterator.next = null;
5353
iterator.value = null;
54+
size--;
5455

55-
return saved;
56+
return removedValue;
5657
}
58+
5759
}

0 commit comments

Comments
 (0)