Question
What will be the output of the following queue implementation using two stacks? class QueueUsingStacks { Stack s1 = new Stack <>(); Stack s2 = new Stack <>(); void enqueue ( int
What will be the output of the following queue implementation using two stacks? class QueueUsingStacks { Stack s1 = new Stack <>(); Stack s2 = new Stack <>(); void enqueue ( int
x) { s1.push(x); } int dequeue () { if (s2.isEmpty()) { while (!s1.isEmpty()) { s2.push(s1.pop()); } } if (!s2.isEmpty()) { return s2.pop(); } throw new RuntimeException ( "Queue is empty!" ); } } QueueUsingStacks queue = new QueueUsingStacks (); queue.enqueue( 1 ); queue.enqueue( 2 ); queue.enqueue( 3 ); System.out.println(queue.dequeue()); queue.enqueue( 4 ); System.out.println(queue.dequeue());
More Data Structure Questions
- A banking application uses a Queue to process customer service requests. The following operations are performed: ENQUEUE(Request_A) → ENQUEUE(Request_B) →...
- A data analysis script receives data in JSON format. Which of the following is a valid JSON data type for a value?
- What is the primary disadvantage of using a singly linked list compared to an array for random access (e.g., accessing the 50th element)?
- In a data analysis application where two sorted linked lists need to be merged into a single sorted linked list, what is the typical time complexity of thi...
- What is the primary goal of the OWASP Top 10 project?
- Which algorithm is used for shortest path in graphs?
- Which search algorithm is complete but not always optimal?
- Which of the following data structures can be efficiently implemented using a linked list?
- Fibonacci heaps support which operation in O(1) amortized time?
- Tarjan’s Algorithm finds:
Hey! Ask a query
Please enter email id
The email must be a valid email address.
Please enter Mobile Number
Please enter valid Mobile Number
Please enter your Doubt
Think You're Ready for RBI Grade B?
RBI Grade B 2026 Phase 1 Memory Based Paper
- 200 Questions with Detailed Solutions
- Section-wise Coverage (GA, English, Quant & Reasoning)