The Gateway to Computer Science Excellence
+9 votes
2.2k 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
in DS by Veteran (106k points) | 2.2k views

2 Answers

+9 votes
Best answer

The correct option is B.

by Active (2.3k points)
selected by
+1
@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.
0
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.
0
it will work for all the cases.
+6 votes
by Veteran (50.9k points)
Answer:

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,737 questions
57,390 answers
198,589 comments
105,443 users