How many stacks are needed to implement a queue. Consider the situation where no other data structure like arrays, linked list is available to you.
1 point
1
2
3
4
Answers
Answered by
18
Answer:
How many stacks are needed to implement a queue. Consider the situation where no other data structure like arrays, linked list is available to you. Explanation: A queue can be implemented using two stacks.
Answered by
1
2 is the correct answer.
A Queue can be implemented through 2 stacks.
A queue involves two operations in it.
- Enqueue: It is the operation to add an element in the queue.
- Dequeue: It is the operation to delete or remove the element in the queue.
Queue follows the FIFO rule. It stands for the First In First Out rule, it means the first element should be treated first.
So, by using two stacks both the operation of enqueue and dequeue can be performed.
Similar questions