- #1
magnifik
- 360
- 0
I am writing code for a doubly linked list, but when I try to compile it, I am getting an error when trying to throw the NoSuchElementException() function. Here is the part of the code concerning the issue:
// _size is an integer that keeps track of the number of elements. in this case, i am checking if the list is empty
public Object removeBack() {
if (_size == 0) {
throw new NoSuchElementException();
}
Node node = new Node();
Node cursor = _tail._prev;
cursor._next._prev = cursor._prev;
cursor._prev._next = cursor._next;
_size--;
}
i am wondering.. what's wrong with it? am i calling it incorrectly?
// _size is an integer that keeps track of the number of elements. in this case, i am checking if the list is empty
public Object removeBack() {
if (_size == 0) {
throw new NoSuchElementException();
}
Node node = new Node();
Node cursor = _tail._prev;
cursor._next._prev = cursor._prev;
cursor._prev._next = cursor._next;
_size--;
}
i am wondering.. what's wrong with it? am i calling it incorrectly?