I find it difficult to understand the second half of connecting a new node to a double-linked list. I am writing an add method that accepts in a node that a new node needs to be inserted. My area of difficulty is understanding how to refer to the next node after the previous node links have been redirected to the new node.
So here where I came up
Chunk<E> newChunk= new Chunk<E>();
newChunk.next= prevChunk.next;
prevChunk.next= newChunk;
newChunk.prev= newChunk.next.prev;
newChunk.next.prev= newChunk;
I understand, since the command newChunk.next= prevChunk.nextcopies the memory address of prevChunk.next and sets this value to newChunk.next, and then prevChunk.next reset to reference newChunk.
So, since prevChunk is the only node listed here that is already in the list and the following fields have been redirected to newChunk, am I on the right path using these links to refer to the next node?