1 1 vote A queue is implemented using two stack A and B. Consider the following code void enqueue(int value) { While (!B.is Empty()) A.push(B.Pop()); A. push (value); } int dequeue () { While (!A.is Empty()) {X} return B.Pop(); } if enqueue is implemented using two stacks A & B With operation Push ,Pop and is empty of stacks then find the missing statement X to implement dequeue operation of the queue . A) A.Push(B.Pop()); B) B.Push(A.Pop()); C) A.Pop(B. Push ()); D) B.Pop(A. Push ()); what is difference between option b,d??? Data Structures queue + – Hira Thakur 1.4k views answer comment Share Follow Print See all 7 Comments 7 7 Comments reply Show 4 previous comments Warlock lord commented Oct 1, 2017 reply Follow flag Yes @hira I'm facing the same problem. The code is not right And @ankush look at the code carefully .. in Enqueue they are first movinf elements from stack B to A and then adding the element to stack A which is wrong. They should first add it only in stack B until deque is called where all elements must be transferred to A and then pop the last element. Because of the above functionality the dequeue is wrong too because if we choose B as the answer and push everything to stack B, we're only getting the initial stack! Meaning the element that will be popped in dequeue is working as stack and not queue. Try dry running the code. 0 0 replyShare ANKUSH KUMAR commented Oct 1, 2017 reply Follow flag @Warlock lord what is wrong in this.let we first insert 1 2 3 sequencially and now 3 is on the top of stack A. now if we want to pop the element than we first push stack A element in stack B and now stack B contain 3 2 1 where 1 is on the top of stack B. and then we pop the element which is 1 in this case. 0 0 replyShare Warlock lord commented Oct 1, 2017 reply Follow flag Oh yes @Ankush I interchanged stack A and B's role when I wrote it down in the notebook.. so sorry Yes then B seems to be the right option 0 0 replyShare Please log in or register to add a comment.