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;