Nevermind . . . I figured it out.
Printable View
Nevermind . . . I figured it out.
Before you do the InsertBefore, current -> prev -> next pointed to current.
But now you're inserting something new (tempNode) before current, so you want to end up with the old current -> prev -> next pointing to tempNode, and tempNode -> next pointing to current, and current -> prev pointing to tempNode.
In your numbers example, AFTER everything is done, if current is 9, current -> prev -> next is 9.
Thanks! I couldn't figure out the code and spent a lot of time trying to figure it out.
There is no point erasing your post after you get an answer, if you figure it out for yourself, you should say how, and leave it because one day someone else might get their answer instead of having to post.