Reverse a Queue Coding Question

Placewit
2 min readMar 15, 2022

Problem Statement:

You have been given a queue that can store integers as the data. You are required to write a function that reverses the populated queue itself without using any other data structures.

Input Format:

The first line input for each test case/query contains an integer N, denoting the total number of elements in the queue.

The second line of input contains N integers separated by a single space, representing the order in which the elements are enqueued into the queue.

Output Format:

For each test case/query, the only line of output prints the order in which the queue elements are dequeued, all of them separated by a single space.

Output for every test case/query will be printed

on a new line.

Sample Input:

6
1 2 3 4 5 10

Note:

Here, 1 is at the front and 10 is at the rear of the queue.

Sample Output :

10 5 4 3 2 1

Code:

Thanks for Reading

Placewit grows the best engineers by providing an interactive classroom experience and by helping them develop their skills and get placed in amazing companies.

Learn more at Placewit. Follow us on Instagram and Facebook for daily learning.

--

--