178. Reverse a Queue
Foundation1000 ms256 MBSolved by 0%
Read n values added to a queue in the order given, reverse the queue, then
print it from FRONT to back.
A queue only lets you take from the front, and only lets you add at the back — so on its own it can never reverse itself. You need one other structure that reverses order, and you have already built exactly that one.
Constraints - `1 ≤ n ≤ 100000` - `-1000000 ≤ value ≤ 1000000`
Input
The first line contains an integer n.
The second line contains n space-separated integers, in the order they are added to the queue.
Output
Print the reversed queue from front to back — n integers on one line, separated by single spaces.
Input3
1 2 3
Output3 2 1
Notereverses a three-value queue
Input1
7
Output7
Noteis a single value, where reversing changes nothing
Hint 1Approach
Hint 2Approach
Hint 3Pseudocode
Hint 4Full solution