Question: Give an implementation of this a LeakyStack abstraction, using circular array with appropriate storage capacity. Modify the code below considering the following requirements and situations:

Give an implementation of this a LeakyStack abstraction, using circular array with appropriate storage capacity. Modify the code below considering the following requirements and situations:

a. The stack size is 5, and the storage capacity is 10.

b. If at a point, the stack (i.e. the inner array of the stack) is as follows: [4, 1, 3, 2, 5, None, None, None, None, None], where 4 is the end of the stack and 5 is the top of the stack, and a new number 8 is pushed in the stack, the stack should be as follows: [None, 1, 3, 2, 5, 8, None, None, None, None, None]. This means 4 is ignored (leaked).

c. If at a point the stack is as follows: [2, 3, None, None, None, None, None, 8, 9, 1], where 8 is the end of the stack and 3 is the top of the stack, and a new number 5 is pushed in the stack, the stack will becomes: [2, 3, 5, None, None, None, None, None, 9, 1]. This means 8 is ignored (leaked).

d. Other special situations should be considered such as performing a pop operation when the stack is empty.

e. The other menu option should be to exit the program. With the menu you should have two options: one to allow the user to change the value of maxlen (the inner array) and the other to rerun the script to see the output with the change. The other menu option should be to exit the program.

A sample output of code should show as per image attached.Give an implementation of this a LeakyStack abstraction, using circular array with

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

class Full(Exception): pass

class Empty(Exception): pass

class MyLeakyStack(): """complete this class by adding more functions within the class""" DEFAULT_CAPACITY = 10 #storage capacity is 10 def __init__(self, maxlen, capacity): """note: this function is partially completed""" self._maxlen = maxlen self._capacity = capacity # size of the circular array self._storage = [None] * capacity # initialise storage room, this is treated as a circular array

def menu(self): """ Either end or change the maxlen of the inner array """

####### don't edit between here and the comment below ######## def run(self): for i in range(12): try: S.push(i) print("after push "+str(i), S._storage) except Exception as e: print(e, " after push "+str(i), S._storage)

for i in range(6): try: a=S.pop() print("after pop "+str(a), S._storage) except Exception as e: print(e, S._storage)

for i in range(5): try: S.push(i+100) print("after push " + str(i+100), S._storage) except Exception as e: print(e, S._storage) ###### don't edit the above lines - add anything below as you with

#### don't add anything below here if __name__ == '__main__': S = MyLeakyStack(5, 10) # stack size should be 5 and the capacity of the array should be 10 S.run()

UPDATE THE CODE FOR the last 11 lines mentioned in the black image of OUTPUT.

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!