Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python question involving stack, queue, and/or deque Give a Python implementation for the MidStack ADT. The MidStack ADT supports the following operations * MidStack ():initializes

Python question involving stack, queue, and/or deque

image text in transcribed

image text in transcribed

Give a Python implementation for the MidStack ADT. The MidStack ADT supports the following operations * MidStack ():initializes an empty MidStack object . midS.is_empty (): returns True if S does not contain any elements, or False otherwise len (midS): Returns the number of elements midS midS.push (e) : adds element e to the top of mids. midS.top (): returns a reference to the top element ofmidS, without removing it; an exception is raised if S is empty midS.pop ):removes and returns the top element from midS; an exception is raised ifmidS is empty . * e midS.mid push (e) : adds element e in the middle of midS That is, assuming there are n elements in S: In the case n is even, e would go exactly in the middle. If n is odd, e will go after the "2th element. For example, your implementation should follow the behavior as demonstrated in the two execution examples below: >>> mdS = MidStack() >>> mids.push (2) >>> midS.push (4) >>> mids.push (6) >>> midS.push (8) >>> mids.mid push (10) >>>midS.pop () >>> midSMidStack ) >>> mids.push (2) >>> midS.push (4) >>> midS.push (6) >>> midS.push (8) >>> mids.push (10) >>>midS.mid push (12) >>>midS.pop () 10 >>>midS.pop () >>>midS.pop () 6 >>>midS.pop () 10 >>> midS.pop () >>>mids.pop ) 12 >>>midS.pop () >>>midS.pop () 2 >>>midS.pop( >>>midS.pop () 2 Give a Python implementation for the MidStack ADT. The MidStack ADT supports the following operations * MidStack ():initializes an empty MidStack object . midS.is_empty (): returns True if S does not contain any elements, or False otherwise len (midS): Returns the number of elements midS midS.push (e) : adds element e to the top of mids. midS.top (): returns a reference to the top element ofmidS, without removing it; an exception is raised if S is empty midS.pop ):removes and returns the top element from midS; an exception is raised ifmidS is empty . * e midS.mid push (e) : adds element e in the middle of midS That is, assuming there are n elements in S: In the case n is even, e would go exactly in the middle. If n is odd, e will go after the "2th element. For example, your implementation should follow the behavior as demonstrated in the two execution examples below: >>> mdS = MidStack() >>> mids.push (2) >>> midS.push (4) >>> mids.push (6) >>> midS.push (8) >>> mids.mid push (10) >>>midS.pop () >>> midSMidStack ) >>> mids.push (2) >>> midS.push (4) >>> midS.push (6) >>> midS.push (8) >>> mids.push (10) >>>midS.mid push (12) >>>midS.pop () 10 >>>midS.pop () >>>midS.pop () 6 >>>midS.pop () 10 >>> midS.pop () >>>mids.pop ) 12 >>>midS.pop () >>>midS.pop () 2 >>>midS.pop( >>>midS.pop () 2

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

Databases And Information Systems 1 International Baltic Conference Dbandis 2020 Tallinn Estonia June 19 2020 Proceedings

Authors: Tarmo Robal ,Hele-Mai Haav ,Jaan Penjam ,Raimundas Matulevicius

1st Edition

303057671X, 978-3030576714

More Books

Students also viewed these Databases questions

Question

Which team solution is more likely to be pursued and why?

Answered: 1 week ago

Question

4. I can tell when team members dont mean what they say.

Answered: 1 week ago