Implement a basic Queue class that supports first-in, first-out (FIFO) ordering. Items added with enqueue are removed in the same order they arrived, like people leaving a line in arrival order.
The class must support these methods:
- enqueue(value): add value to the back of the queue
- dequeue(): remove and return the front value, or null if the queue is empty
- size(): return the number of items currently in the queue
Input
A sequence of operation names with their arguments, applied to a single Queue instance.
Output
A list of return values, one per operation. The constructor returns null.
Examples
Example 1
Input["Queue", "enqueue", "enqueue", "size", "dequeue"]
[[], [10], [20], [], []]
Output[null, null, null, 2, 10]
Explanation: After enqueuing 10 then 20, size is 2 and dequeue returns the oldest item (10).
Constraints
Enqueue, dequeue, and size should run in O(1) amortized time.
Dequeue on an empty queue must return null rather than throwing.