525 views
1 votes
1 votes

I have a doubt regarding " implementing queue using 2 stacks "
  For an EQueue operation there is a push operation in one of the stack  that is OK
but when we are doing first DQueue operation why we need to pop each element from from one stack and push all into other stack rather than pop elements from one stack until it has one element and after that pop that element from the same stack .

1 Answer

1 votes
1 votes
Because if you won't push them onto 2nd stack you will lose elements after first one.  So when you perform dequeue next time from where will second element come so that we can dequeue it

Related questions

7 votes
7 votes
1 answer
1
junaid ahmad asked Oct 31, 2017
3,975 views
Q.What will be time complexity of enqueue and dequeue operation when a queue is implemented using two stacks.
1 votes
1 votes
2 answers
2
Tushar Shinde asked Dec 7, 2015
2,436 views
Which of the following statement is/are correct?1. If we use only Front pointer in queue, then insertion takes O(n) time while deletion in O(1) time.2. If we use only Rea...