Last active
May 12, 2018 20:39
-
-
Save scriptpapi/e6a0c6e44061474aba63e1a2e59bd30f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Basic stack implementation | |
class Stack: | |
def __init__(self): | |
self.items = list() | |
def isEmpty(self): | |
return self.items == [] | |
def push(self, data): | |
self.items.append(data) | |
def pop(self): | |
return self.items.pop() | |
def size(self): | |
return len(self.items) | |
def getTop(self): | |
return self.items[len(self.items)-1] | |
def getBottom(self): | |
return self.items[0] | |
def find(self, value): | |
if value in self.items: | |
return self.items.index(value) | |
else: | |
return False | |
# Test cases | |
""" | |
s1 = Stack() | |
s1.isEmpty() | |
s1.push(5) | |
s1.push("josh") | |
s1.push(12.90) | |
s1.push("louie") | |
print(s1.getTop()) | |
print(s1.getBottom()) | |
print(s1.size()) | |
print(s1.pop()) | |
print(s1.size()) | |
print(s1.find("josh")) | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment