Question: What is the solution to this question using Object Oriented Programming? Give an implementation of this LeakyStack abstraction, using circular array with appropriate storage capacity
What is the solution to this question using Object Oriented Programming?
Give an implementation of this LeakyStack abstraction, using circular array with appropriate storage capacity.
Modify the code below considering the following requirements and situations:
- The stack size is 5, and the storage capacity is 10.
- 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).
- 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 become: [2, 3, 5, None, None, None, None, None, 9, 1]. This means 8 is ignored (leaked).
- Other special situations should be considered such as performing a pop operation when the stack is empty.
- 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.
# 1) The class is incomplete and is missing methods. # 2) Need to add methods to make this a circular array. # 3) Need to complete the init method. # 4) Lastly, add a method to create a menu so the user can modify maxlen. # 5) With the menu you should have two options: one to change maxlen, # 6) and the other to rerun the script to see the output with the change.
________________________________________________________
#code
class Full(Exception): pass
class Empty(Exception): pass
class MyLeakyStack(): """complete this class by adding more functions within the class""" 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
Step by Step Solution
There are 3 Steps involved in it
To implement the LeakyStack abstraction using a circular array we will create a class with methods to push and pop elements adhering to the specified behavior along with a menu to allow dynamic change... View full answer
Get step-by-step solutions from verified subject matter experts
