Skip to content

Commit eb414a1

Browse files
authored
Update QueueUsingTwoStacks.java
1 parent c07fac8 commit eb414a1

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

QueueUsingTwoStacks.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
/*
2+
Problem Statement: Implement a Queue Using Two Stacks
3+
The task is to implement a queue using two stacks. A queue follows a First-In-First-Out (FIFO) structure,
4+
where elements are enqueued at the rear and dequeued from the front. The program will process a series of queries that either enqueue an element,
5+
dequeue an element, or print the element at the front of the queue.
26
7+
Implement must follow three types of queries:
8+
1 x: Enqueue element x into the end of the queue.
9+
2: Dequeue the element from the front of the queue.
10+
3: Print the element at the front of the queue.
11+
12+
Input:
13+
The first line contains an integer q (the number of queries).
14+
Each of the following q lines contains a query of one of the three types mentioned above.
15+
16+
Output:
17+
For each query of type 3, print the element at the front of the queue.
18+
19+
Constraints:
20+
It is guaranteed that all dequeue and print operations will be valid, i.e., the queue will never be empty when such operations are performed.
321
*/
422

523
import java.io.*;

0 commit comments

Comments
 (0)