addFirst() in a custom LinkedList
I'm working with a LinkedList of customLinkedLists and I'm having some
problems with the implementation of my AddFirst method.
Here's the method,
public void addFirst(GenericType data)
{
Node<GenericType> toAdd = new Node<GenericType>(data);
if(sizeCounter != 0)
{
toAdd.next = head;
head = toAdd;
sizeCounter++;
} else {
head = add;
tail = add;
toAdd.next = null;
sizeCounter++;
}
}
The problem is this increments the size correctly every time i call it,
but when I try to print out the values, it throws a null pointer
exception. I know there's a problem in the way I'm setting the head/tail
pointer but I cant figure out what it is exactly.
No comments:
Post a Comment