GATE CSE
First time here? Checkout the FAQ!
x
+4 votes
566 views

The queue data structure is to be realized by using stack. The number of stacks needed would be

  1. It cannot be implemented
  2. 2 stacks
  3. 4 stacks
  4. 1 stack
asked in DS by Veteran (76.2k points)   | 566 views

2 Answers

+4 votes
answered by Veteran (46.4k points)  
+1 vote

The correct option is B.

answered by Active (2.2k points)  
@pankaj kumaras you have written if we want to perform queue operation then we need to pop ...but actually for queuing you don't need to pop you just need to push the elements in stack A like push a then push b push c this is for queuing but for dequeuing you must pop them from stack A and push them into B now for dequeuing pop then one by one to maintain the queue order.
you are right but the case is after insertion some element we want to remove an element from the queue and then again we want insertion that's why i did this.
it will work for all the cases.


Top Users Apr 2017
  1. akash.dinkar12

    3514 Points

  2. Divya Bharti

    2546 Points

  3. Deepthi_ts

    2040 Points

  4. rude

    1966 Points

  5. Tesla!

    1768 Points

  6. Shubham Sharma 2

    1610 Points

  7. Debashish Deka

    1588 Points

  8. Arunav Khare

    1454 Points

  9. Kapil

    1424 Points

  10. Arjun

    1420 Points

Monthly Topper: Rs. 500 gift card

22,076 questions
28,042 answers
63,233 comments
24,135 users