- #1
magnifik
- 360
- 0
i am trying to remove an element from the back of the list (i.e. the node right before the tail). i am using a dummy head and tail node. the code compiles correctly, but when i try to test it, there is no execution. below is the segment of code that i am referring to:
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; // this is the line of code giving me error
_size--;
return node._data;
}
i am not sure what is wrong with my code. it works properly when trying to removeFront, and the only change from that segment of the code is the cursor.
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; // this is the line of code giving me error
_size--;
return node._data;
}
i am not sure what is wrong with my code. it works properly when trying to removeFront, and the only change from that segment of the code is the cursor.