2,477 views
3 3 votes

PLEASE PROVIDE SOURCE FOR THIS CONCEPT

Suppose that queue operations are implemented using stack operation. enqueue(x) and Dequeue( ) are queue operations whereas Pop( ) and Push(x) are stack operations. Consider the following code

Enqueue(S1,x){
  Push(S1,x);
}
Dequeue(S1,S2){ 
  if(!IsEmptyStack S2)
    return Pop(S2);
  else{
    while(!IsEmptyStack S1)
      B1;
   return B2;
  }
}

Fill the missing statement B1 and B2 to perform Dequeue operation correctly (here S1 and S2 are two stacks)

(A) Push (S2, Pop (S1)); and S2;
(B) Push (S1, Pop (S2)); and S1;
(C) Push (S1, Pop (S2)); and S2;
(D) Push (S2, Pop (S1)); and S1;

1 Answer

Position:
Show:

Related questions

3 3 votes
3 3 answers
8.6k
8.6k views
Ibtisam Sayyad asked Jan 12, 2018
8,557 views
What are the minimum enqueue and dequeue operations needed to perform pop operation for a stack which is implemented with two queues if there are already 10 elements in t...
8 8 votes
3 3 answers
344
344 views
GO Classes asked Jul 8
344 views
A queue is implemented using two stacks $\text{S1}$ and $\text{S2}$.Use the implementation where $\texttt{dequeue()}$ is $\text{O(1)}$ by keeping the front of the queue a...
6 6 votes
1 answers 1 answer
5.7k
5.7k views
junaid ahmad asked Oct 31, 2017
5,664 views
Q.What will be time complexity of enqueue and dequeue operation when a queue is implemented using two stacks.
1 1 vote
1 1 answer
1.8k
1.8k views
amit166 asked Jan 6, 2019
1,782 views
How many enqueue and dequeue operations are required to perform a pop operation if Q1 contains n element initially?