Skip to content

Commit 1dbbb23

Browse files
committed
Fix for Issue TheAlgorithms#771. position=size causes NPE
1 parent 163db85 commit 1dbbb23

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

DataStructures/Lists/SinglyLinkedList.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,12 @@ public void deleteHead() {
6666
}
6767

6868
/**
69-
* This method deletes an element at Nth position
70-
*/
69+
* This method deletes an element at Nth position
70+
*/
7171
public void deleteNth(int position) {
72-
if (position < 0 || position > getSize()) {
72+
if (position < 0 || position >= getSize()) {
7373
throw new RuntimeException("position less than zero or position more than the count of list");
74-
}
75-
else if (position == 0)
74+
} else if (position == 0)
7675
deleteHead();
7776
else {
7877
Node cur = head;

0 commit comments

Comments
 (0)