Build Both Ends of a Deque
mediumQuestion 456A deque has four doors: add and remove at each end. Lock two of them and the same class becomes something familiar - addFirst with removeFirst is a stack, addLast with removeFirst is a queue. LinkedDeque already gives you isEmpty, size and toString; write the four operations.
Requirements:
1. addFirst(int value) and addLast(int value) link a new DNode at that end and grow the size.
2. removeFirst() and removeLast() unlink that end and return its value, or return -1 when the deque is empty.
3. head, tail and size must stay in agreement, so a deque drained to empty can be filled again from either end.
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
3 -> 2 -> 1 -> null 3 2 1 -1 null 0 10 -> 20 -> 30 -> null 10 20 -> 30 -> 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...