Fix for Issue #771. position=size causes NPE

This commit is contained in:
Abhijay Kumar 2019-05-29 16:53:42 +05:30
parent 163db8521a
commit 1dbbb23cfd

View File

@ -69,10 +69,9 @@ class SinglyLinkedList {
* This method deletes an element at Nth position
*/
public void deleteNth(int position) {
if (position < 0 || position > getSize()) {
if (position < 0 || position >= getSize()) {
throw new RuntimeException("position less than zero or position more than the count of list");
}
else if (position == 0)
} else if (position == 0)
deleteHead();
else {
Node cur = head;