Implement Queue using Arrays

Implement a first-in-first-out queue in the ArrayQueue class using an array. The no-argument constructor creates an empty queue. push(x) adds x at the rear;…

Implement a first-in-first-out queue in the ArrayQueue class using an array. The no-argument constructor creates an empty queue. push(x) adds x at the rear; pop() removes and returns the front; peek() returns the front without removal; isEmpty() reports whether the queue has no elements. Empty pop and peek return -1. Input contains equally sized operations and arguments arrays, with ArrayQueue first and exactly one argument array per call. Return one result per call: null for construction and push, an integer for pop/peek, and a boolean for isEmpty.

- 1 <= operations.length <= 100, including the initial constructor. - arguments.length equals operations.length; method names and arities must match. - 1 <= x <= 100 for every push; all other calls take no arguments. - There is exactly one constructor, at position zero. - Empty pop/peek are permitted and return -1 without mutation. - Fixed capacity 100 covers every valid sequence; there is no ten-item limit. - Visualization presets contain at most 12 calls; grading retains the full domain.

Example 1: input operations = ["ArrayQueue","push","push","pop","push","peek","pop","pop"], arguments = [[],[4],[8],[],[5],[],[],[]]; output [null,null,null,4,null,8,8,5]. After removing 4, adding 5 does not overtake 8. Peek leaves 8 in place, so the next pop also returns 8.

Example 2: input operations = ["ArrayQueue","pop","peek","isEmpty"], arguments = [[],[],[],[]]; output [null,-1,-1,true]. Empty reads return -1 and do not add or remove anything. The final emptiness check is true.

Example 3: input operations = ["ArrayQueue","push","pop","isEmpty","push","peek","pop","isEmpty"], arguments = [[],[7],[],[],[9],[],[],[]]; output [null,null,7,true,null,9,9,true]. Draining resets both ends. Enqueueing 9 reinitializes the empty queue, and peek does not remove it.

Category: Queues. Topic: queue. Difficulty: Easy.