Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a85f252

Browse filesBrowse files
committed
fix remove method
1 parent c4a8e1e commit a85f252
Copy full SHA for a85f252

File tree

Expand file treeCollapse file tree

1 file changed

+6
-4
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+6
-4
lines changed
Open diff view settings
Collapse file

‎DataStructures/Lists/CircleLinkedList.java‎

Copy file name to clipboardExpand all lines: DataStructures/Lists/CircleLinkedList.java
+6-4Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.