Remove the First Node of a Doubly Linked List
easyQuestion 561Removing the first node of a doubly linked list has one step more than in a singly linked list: the node that becomes the new head still holds a prev link to the node being dropped, and that link has to be cleared. The empty check and the line that saves the value are written for you.
Requirements:
1. removeFirst() unlinks the first node and returns the value it held, or -1 on an empty list.
2. When only one node is left, head and tail both become null.
3. Otherwise head moves onto the next node, and the prev link of that new head is set to null so that a backward walk ends there.
4. size goes down by one.
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
10 20 -> 30 -> null 30 -> 20 -> null 2
= newline. The output ends with a newline, so print one after the last line.
Your output
Run your code to see the output here...