Skip to content

Instantly share code, notes, and snippets.

@hoanbka
Last active October 26, 2017 06:16
Show Gist options
  • Save hoanbka/36d7b266cbb243739e186b674f5b9fd3 to your computer and use it in GitHub Desktop.
Save hoanbka/36d7b266cbb243739e186b674f5b9fd3 to your computer and use it in GitHub Desktop.
Implementation of a simple STACK
class Stack():
def __init__(self):
self.arr = []
def push(self, item):
self.arr.append(item)
def pop(self):
if self.arr:
self.arr.pop()
else:
return 'Empty stack'
def poll(self):
if self.arr:
return self.arr[-1]
else:
return 'Empty stack'
def size(self):
return len(self.arr)
def __str__(self):
return (str((self.arr)))
s = Stack()
s.push(2)
s.push(3)
print(s)
s.pop()
print(s)
print([1, 2, 3, 4])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment