Your remove
method doesn't actually work when value of index
is 0
.. Because both your node
and prev
are initialized to front
and the loop is not being executed because the i<index
condition is false. So you have to add another condition for the case of index=0
Adding these lines at the starting of your remove
method solves the problem..
if(index==0){
ListNode<integer>temp=front;
front=front.getNext();
return temp.getItem();
}
hope it helped...