Created
April 30, 2020 03:18
-
-
Save avivajpeyi/91dda5afc37c02dbccb474cf80d0e0cc 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
from stack import Stack | |
def lecuture_test_1(): | |
out_string = "" | |
int_stack = Stack() | |
int_stack.push(1) | |
int_stack.push(2) | |
out_string += f"{int_stack.pop()} , " | |
int_stack.push(3) | |
out_string += f"{int_stack.pop()} , " | |
out_string += f"{int_stack.pop()} " | |
print(out_string) | |
def lecuture_test_2(): | |
int_stack = Stack() | |
int_stack.push(1) | |
int_stack.push(2) | |
print(int_stack.pop(), end=",") | |
print(int_stack.pop(), end=",") | |
print(int_stack.pop()) | |
int_stack.push(3) | |
def main(): | |
print("TEST 1") | |
lecuture_test_1() | |
# print("TEST 2") | |
# lecuture_test_2() | |
if __name__ == '__main__': | |
main() |
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
import logging | |
logging.basicConfig(level=logging.DEBUG) | |
class Stack: | |
def __init__(self): | |
self.the_stack = [] | |
self.count = 0 | |
logging.debug(f"Initialised stack: {self}") | |
def __str__(self): | |
return f"Stack: {self.the_stack} (len:{self.count})" | |
def __len__(self): | |
return self.count | |
def is_empty(self): | |
return self.count == 0 | |
def push(self, item): | |
self.the_stack.append(item) | |
self.count += 1 | |
logging.debug(f"Pushed {item} to stack: {self}") | |
def pop(self): | |
assert not self.is_empty() | |
self.count -= 1 | |
popped_element = self.the_stack.pop() | |
logging.debug(f"Popped top element {popped_element} off stack: {self}") | |
return popped_element | |
def peek(self): | |
assert not self.is_empty() | |
return self.the_stack[-1] |
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 Stack: | |
def __init__(self): | |
self.the_stack = [] | |
self.count = 0 | |
def __len__(self): | |
return self.count | |
def is_empty(self): | |
return self.count == 0 | |
def push(self, item): | |
self.the_stack.append(item) | |
self.count += 1 | |
def pop(self): | |
assert not self.is_empty() | |
self.count -= 1 | |
popped_element = self.the_stack.pop() | |
return popped_element | |
def peek(self): | |
assert not self.is_empty() | |
return self.the_stack[-1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment