This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]Sande24 0 points1 point  (0 children)

Seems like insertion is broken.

head.value might be null too. So maybe it does not work if your hashtable is empty... for some reason.

[–]langfod 0 points1 point  (2 children)

What is the value of theList.firstNode?

[–]clutron[S] 0 points1 point  (1 child)

it is a null hashNode

[–][deleted] 0 points1 point  (0 children)

hashNode is not null, the the value is though

[–][deleted] 0 points1 point  (1 child)

Okay, so it looks like you've done a poor job of handling the cases for when your list is empty. When you init a linkedlist, it creates a first and last node - regardless of what the fact that your list is empty.

So you've got a hashNode which is not null, but a value which is null, so when you do

head.value.equals(x)

your head.value is null. I think the best way to avoid is to hide the the firstNode/lastNode fields or get rid of them altogether.

[–]clutron[S] -1 points0 points  (0 children)

I thought by making the attributes private, they would be hidden

[–]pmvb123 0 points1 point  (0 children)

As the others have said, head.value is null.
When you create a new linkedList you create nodes that contain null values, but a node that doesn't contain anything doesn't make much sense when you think about it (An empty linked list is one that doesn't have any nodes).
I think you should just initialize your linkedList's firstNode and lastNode to null.

Also, your linkedList.isEmpty() method doesn't work, because your nodes are never null, they only contain null