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 traversal method visits the root node first in trees?
- Fibonacci heaps support which operation in O(1) amortized time?
- What is the difference between 'BFS' (Breadth-First Search) and 'DFS' (Depth-First Search) in graph traversal?
- What is the space complexity of storing an adjacency matrix for a graph with V vertices and E edges?
- Which of the following best describes Abstraction in Object-Oriented Programming (OOP)?
- Which of the following is an effective countermeasure against Cross-Site Scripting (XSS) attacks in a web application?
- Which I/O scheduling algorithm is most suitable for minimizing seek time in hard drives?
- Which of the following is a core characteristic of Big Data?
- What is the postorder traversal of the BST built by inserting 50, 30, 70, 20, 40, 60, 80, 10 in this order?
- Which traversal of a binary tree visits the nodes in the order: Left subtree, Root, Right subtree?
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)