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 Warlock lord commented Oct 1, 2017 reply Follow flag I am not sure about the difference but this program is surely wrongly implemented. The enque doesn't make sense. And also in the options how can a push not have a parameter? 0 0 replyShare ANKUSH KUMAR commented Oct 1, 2017 reply Follow flag option b is the answer . for enqueue we assure that last pushed element is at the top of A and then we push the current pushed value in stack A. And for dequeue we push all the element of A in B that mean last pushed element in A is at last in B. and then we pop the first element of B. BY doing this we taking care of first pushed element is deleted first (FIFO) 0 0 replyShare Hira Thakur commented Oct 1, 2017 reply Follow flag Warlock lord i'm unable to relate the given option to the question> 0 0 replyShare ANKUSH KUMAR commented Oct 1, 2017 reply Follow flag D option doesn't make any sense. push operation require value to be pushed and pop operation don't need any argument bcoz it pop the first element of queue. so option c and d is not possible. 0 0 replyShare 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.