[solved]-Code Python Create Class Called Arrayleakystack Based Instructions Q39051664
How to code this in Python??? Create a class calledArrayLeakyStack based on the instructions below.


LeakyStack 2 A Leaky Stack is similar to a stack except that the Leaky Stack has a bound on the number of items that can be stored in it at once. During initialization, the maximum size N is given. If the Leaky Stack has N elements, it is considered full. When an element is added to a Leaky Stack that is full, the element at the bottom of the stack is removed to make room for the new element, which is then placed at top of the stack as usual For example, consider the following code: leaky s LeakyStack(5) leaky_s.push(17) leaky s.push (42) leaky s.push(6) leaky_s.push(31) leaky s.push(28) The Leaky Stack has a maximum size of 5 (specified when it is created with the constructor) so it is now full (because we have pushed 5 items onto it). If we now make a call to leaky s.push (2) , the item at the bottom of the stack, 17, is removed to make space for the new item, 2. This is shown below, where we show the contents of the Leaky Stack both before and after the call to leaky s.push (2): Before: Before: 28 2 28 31 31 6 12 6 42 A class that implements the Leaky Stack ADT would need to provide the following methods: def _init__(self, max_num_of_elems) Initialize an emp ty leaky stack ‘ ‘ ‘ def _len__(self): Return the number of elements in the stack ‘ ‘ ‘ def is_empty (self) Returns True if the stack is empty” def push (self, elem): 1. Implement a Leaky Stack using a dynamic array, in a class called class ArrayLeakyStack. All operations must run in time O(1) in the worst case. Hint: To handle the “leaky” part of removing the bottom element when pushing to a full stack, think of using a similar “circular” approach as we did with queues. Show transcribed image text LeakyStack 2 A Leaky Stack is similar to a stack except that the Leaky Stack has a bound on the number of items that can be stored in it at once. During initialization, the maximum size N is given. If the Leaky Stack has N elements, it is considered full. When an element is added to a Leaky Stack that is full, the element at the bottom of the stack is removed to make room for the new element, which is then placed at top of the stack as usual For example, consider the following code: leaky s LeakyStack(5) leaky_s.push(17) leaky s.push (42) leaky s.push(6) leaky_s.push(31) leaky s.push(28) The Leaky Stack has a maximum size of 5 (specified when it is created with the constructor) so it is now full (because we have pushed 5 items onto it). If we now make a call to leaky s.push (2) , the item at the bottom of the stack, 17, is removed to make space for the new item, 2. This is shown below, where we show the contents of the Leaky Stack both before and after the call to leaky s.push (2): Before: Before: 28 2 28 31 31 6 12 6 42 A class that implements the Leaky Stack ADT would need to provide the following methods: def _init__(self, max_num_of_elems) Initialize an emp ty leaky stack ‘ ‘ ‘ def _len__(self): Return the number of elements in the stack ‘ ‘ ‘ def is_empty (self) Returns True if the stack is empty” def push (self, elem):
1. Implement a Leaky Stack using a dynamic array, in a class called class ArrayLeakyStack. All operations must run in time O(1) in the worst case. Hint: To handle the “leaky” part of removing the bottom element when pushing to a full stack, think of using a similar “circular” approach as we did with queues.
Expert Answer
Answer to How to code this in Python??? Create a class called ArrayLeakyStack based on the instructions below. … . . .
OR

