Java Collections | Set 9 (Queue)
Submissions: 590   Accuracy:

36.29%

  Difficulty: Basic   Marks: 1

Implement different operations on a queue q .

Input:
The first line of input contains an integer T denoting the no of test cases . Then T test cases follow. The first line of input contains an integer Q denoting the no of queries . Then in the next line are Q space separated queries .
A query can be of four types 
1. a x (Pushes an element x at the end of the queue q )
2. r (if queue is not empty pops the front element and prints it, else prints -1)
3. s (prints the size of the queue)
4. p (if queue is not empty prints the front element of the queue, else prints -1)

Output:
The output for each test case will  be space separated integers denoting the results of each query . 

Constraints:
1<=T<=100
1<=Q<=100

Example:

Input
2
5
a 5 a 10 a 15 r p
4
a 5 r p s 
 
Output:

5 10 
5 -1 0 

EXPLANATION:

In test case 1:  In first query 5 is added to the queue.In second query 10 is added to the queue. In third query 15 is added to the queue. In fourth query 5 is removed from the queue and printed.In last query front element of the queue is printed i.e. 10.

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: S_A
Author: saksham0751


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.