Last active
February 4, 2022 00:13
-
-
Save seanjensengrey/0d5a75e9adcd5aabe569f6d6db165a5c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class StackModule: | |
def __init__(self): | |
self.items = [] | |
def __repr__(self): | |
return repr(self.items) | |
def push(self, value): | |
self.items.append(value) | |
def pop(self): | |
return self.items.pop() | |
def add(self): | |
right = self.pop() | |
left = self.pop() | |
self.push(left + right) | |
def sub(self): | |
right = self.pop() | |
left = self.pop() | |
self.push(left - right) | |
def mul(self): | |
right = self.pop() | |
left = self.pop() | |
self.push(left * right) | |
def div(self): | |
right = self.pop() | |
left = self.pop() | |
self.push(left / right) | |
def rotate(self): | |
left = self.items[1:] | |
right = [self.items[0]] | |
self.items = left + right | |
def swap(self): | |
self.items[-2:] = self.items[-2:][::-1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment