Welcome to the Ranch
Thank you for using the code tags, but you didn't quite get them right (see
this link): don't worry, I can correct that for you since you are new.
Remember the structure of a linked list.
Current node ≡ nextNode.prev
and
nextNode ≡ Current node.next
So we assume you already have the appropriate place marked by having a ”live” reference to the current node. What you need to do is add a new node such that:-
Current node.next ≡ newNodenewNode.next ≡ (old)nextNodenewNode.prev ≡ Current node(old)nextNode.prev ≡ newNodeDon't try methods out in a large class. Create a small class that has the requisite features and try it out in that first. You can do that with two old nodes and one new node to insert between them. Once you have done that, you can copy the technique into your larger class.
I don't think what you are doing is going to work. Find the place to insert a new value
before you create the new node. The new node should point to its two neighbouring nodes, not the end nodes. Then you can make the neighbouring modes point to the new node. Remember that if you get to the end node, its
next field will point to
null, so you cannot find a
prev field to point to the new node.
I think maybe you should make the node class private.
All the above applies to an addBefore method, except that you look for end nodes the other way and
prev might point to
null.