Question: here is the stacks.py code class Empty(Exception): pass class Stack(object): Array based LIFO Stack data structure. def __init__(self): self._data = [] def __len__(self): return len(self._data)
here is the stacks.py code
class Empty(Exception): pass
class Stack(object): """Array based LIFO Stack data structure."""
def __init__(self): self._data = []
def __len__(self): return len(self._data)
def is_empty(self): return len(self) == 0
def push(self, e): self._data.append(e)
def top(self): if self.is_empty(): raise Empty("Stack is empty.") return self._data[-1]
def pop(self): if self.is_empty(): raise Empty("Stack is empty.") return self._data.pop()
if __name__ == "__main__": pass # your test can be done here
Implement a recursive method for removing all the elements from a stack. Test your implementation your method by creating a stack from Stacks-py and running
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
