Question
reviously you have implemented the Queue ADT using a Python list as the underlying data structure. Another possible implementation of the Queue ADT involves using
reviously you have implemented the Queue ADT using a Python list as the underlying data structure. Another possible implementation of the Queue ADT involves using two Stack objects - this is illustrated in the diagram below where the stacks are named "in_stack" and "out_stack":
Define a Queue class which implements the following four standard Queue ADT methods:
enqueue(), dequeue(), is_empty(), size()
Your implementation must not use a Python list. Instead, you must use two stacks to implement these operations. Do not implement the Stack class. It will be provided for you. You can use any of the standard Stack ADT methods:
Stack(), push(), pop(), is_empty(), size().
The class structure should be as follows, note that the init() method (which creates the two stacks) has been defined for you:
class Queue: def __init__(self): self.in_stack = Stack() self.out_stack = Stack() def is_empty(self): def enqueue(self, item): def dequeue(self): def size(self):
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started