Insert After a Node in a Doubly Linked List
easyQuestion 562Inserting in the middle of a doubly linked list never shifts anything. It rewires four links: the two that belong to the new node, and one on each neighbour. The order matters, because once before.next is changed, the node that used to follow can no longer be reached through before. The helper find and the first lines of the method are written.
Requirements:
1. insertAfter(int target, int value) puts a new node holding value right after the first node that holds target, and returns true.
2. The new node points back at before and forward at the node that used to follow before.
3. When before was the last node, tail moves onto the new node. Otherwise the node that used to follow before points back at the new node.
4. Last of all, before points forward at the new node and size goes up by one.
5. Keep the given check that returns false when no node holds target.
The DNode class is provided. Do not rename it and do not add public to it, because a Java source file may contain only one public class.
Do NOT write a main method.
Expected output
true 10 -> 20 -> 30 -> 40 -> null 40 -> 30 -> 20 -> 10 -> null 4
= newline. The output ends with a newline, so print one after the last line.
Your output
Run your code to see the output here...