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

Python question involving stack, queue, and/or deque Give a Python implementation for

the MidStack ADT. The MidStack ADT supports the following operations * MidStack

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!