This can not work. I guess, it does not get to execute the follwoing part at all:
first = null;
first.setNext(null);
The reason i sthat this would raise a NullpointerException. You first set the first
to null and than try to dereference the null
.
I will not provide you the exact code (as this is some kind of homework right? ;)), but check this pseudo code from wikipedia (http://en.wikipedia.org/wiki/Doubly_linked_list):
function remove(List list, Node node)
if node.prev == null
list.firstNode := node.next
else
node.prev.next := node.next
if node.next == null
list.lastNode := node.prev
else
node.next.prev := node.prev
destroy node