Answered step by step
Verified Expert Solution
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
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 () 2Step 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