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
- Which graph traversal algorithm uses a queue to explore vertices in a layer-by-layer fashion?
- What is the tight asymptotic time complexity of building a binary min-heap from an unsorted array of n elements using the standard bottom-up heapify approa...
- What will be the output of the following queue implementation using two stacks? class QueueUsingStacks { Stack s1 = new Stack <>(); Stack ...
- If an algorithm takes $5n² + 3n + 10$ steps for an input of size n, its Big O notation would be:
- Which feature of OOP allows hiding implementation details while showing only the necessary functionality?
- Which of the following is the main objective of the 3rd Normal Form (3NF) in database normalization?
- What is the primary purpose of a data structure?
- What is the worst-case time complexity of the Bubble Sort algorithm?
- Which of the following is a key objective of the Requirement Analysis phase in the Software Development Lifecycle (SDLC)?
- Max-Flow Min-Cut theorem states:
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)