Given a queue represented as a list of integers, implement a function that reverses the order of the elements in the queue. You are only allowed to use basic queue operations such as enqueue (adding to the end) and dequeue (removing from the front). Although you may use an auxiliary data structure if needed (e.g., a stack), try to keep the solution straightforward.
Example:
If the input queue is [1, 2, 3, 4, 5]
(where 1
is at the front), the reversed queue should be [5, 4, 3, 2, 1]
.
Note:
Happy November 16! Today, as many commemorate important milestones and cultural histories, take a moment to appreciate the elegance of simple algorithms that power everyday operations.