Use app×
QUIZARD
QUIZARD
JEE MAIN 2026 Crash Course
NEET 2026 Crash Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
222 views
in Information Technology by (106k points)
closed by
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

1 Answer

0 votes
by (103k points)
selected by
 
Best answer
Correct Answer - Option 2 : 2 stacks

The correct answer is option 2:

Method 1 (efficient push):

  • push:
    • enqueue in queue1
  • pop:
    • while the size of queue1 is bigger than 1, pipe dequeued items from queue1 into queue2
    • dequeue and return the last item of queue1, then switch the names of queue1 and queue2

Method 2 (efficient pop):

  • push:
    • enqueue in queue2
    • enqueue all items of queue1 in queue2, then switch the names of queue1 and queue2
  • pop:
    • deqeue from queue1

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...