Add to the Front of a Doubly Linked List
easyQuestion 559In a doubly linked list every DNode has a prev link as well as a next link. A new first node therefore needs two links wired, one in each direction, before head moves onto it. addLast is already written and shows the same idea at the other end.
Requirements:
1. addFirst(int value) puts a new node at the front of the list.
2. On an empty list the new node becomes both head and tail.
3. Otherwise the new node points forward at the old head, the old head points back at the new node, and head moves onto the new node.
4. size goes up by one in both cases.
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 -> 10 -> null 3
= newline. The output ends with a newline, so print one after the last line.
Your output
Run your code to see the output here...