# Data Structure Questions and Answers-Stack using Queues

## Click on any option to know the CORRECT ANSWERS

 Question 6
Making the pop operation costly, select the code snippet which implements the same.
 A public int pop() { int res=-999, count=0; if(q1.size()>0) { count = q1.size(); public int pop() { int res=-999, count=0; if(q1.size()>0) { count = q1.size(); public int pop() { int res=-999, count=0; if(q1.size()>0) { count = q1.size();  D None of the mentioned

Question 6 Explanation:
Here the pop operation is costly, hence we need two queues, other than the first element, all the the elements from one queue are dequeued and enqueued to the second queue, hence only one element remains in the first queue which is the item we want, so dequeue it and return the result.

 Question 7
What is the functionality of the following piece of code?

public void fun(int x) { 	q1.offer(x); }
 A Perform push() with push as the costlier operation B Perform push() with pop as the costlier operation C Perform pop() with push as the costlier operation D Perform pop() with pop as the costlier operation