1,777 views
3 votes
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

Related questions

7 votes
7 votes
1 answer
1
junaid ahmad asked Oct 31, 2017
3,938 views
Q.What will be time complexity of enqueue and dequeue operation when a queue is implemented using two stacks.
3 votes
3 votes
3 answers
2
Ibtisam Sayyad asked Jan 12, 2018
7,870 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...
1 votes
1 votes
1 answer
3
amit166 asked Jan 6, 2019
1,378 views
How many enqueue and dequeue operations are required to perform a pop operation if Q1 contains n element initially?