Build Both Ends of a Linked Queue
mediumQuestion 442LinkedQueue adds at the tail and removes at the head, so the two missing methods must keep head, tail and size telling the same story.
Requirements:
1. enqueue(int value): link a new Node on at the tail, point head and tail at it when the queue was empty, and grow size.
2. dequeue(): return -1 when empty, otherwise save head.value, move head on, shrink size and return the saved value.
3. When dequeue() removes the last node, tail must go back to null - otherwise the next enqueue hangs off a node that has left the queue and the value is lost.
The Node 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 10 20 30 null 0 40 -> 50 -> null 40 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...