Question: **PYTHON** Colab(ipynb) Using the Stack class provided, write a method invert() to invert the contents of the stack. You may use additional stacks in your
**PYTHON**
Colab(ipynb)
Using the Stack class provided, write a method invert() to invert the contents of the stack. You may use additional stacks in your function. Note: If the number 3 is at the top of the stack s, after calling s.invert(), 3 will be at the bottom of s.
class Stack: def __init__(self): def push(self, value): def pop(self)
class Stack:
def __init__(self):
self.top = -1
#this stack is implemented with Python list (array)
self.data = []
def push(self, value):
#increment the size of data using append()
self.data.append(0)
self.top += 1
self.data[self.top] = value
def pop(self):
value = self.data[self.top]
#delete the top value using del
del self.data[self.top]
self.top -= 1
return value
def isEmpty(self):
return (self.top == -1)
def peek(self):
pass
def printStack(self):
print(self.data)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
