Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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":

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Datalog Engines In Databases

Authors: Bas Ketsman ,Paraschos Koutris

1st Edition

1638280428, 978-1638280422

More Books

Students also viewed these Databases questions