Skip to content

Instantly share code, notes, and snippets.

@rehrumesh
Created May 2, 2015 05:04
Show Gist options
  • Save rehrumesh/5d2621e22deb08207ca1 to your computer and use it in GitHub Desktop.
Save rehrumesh/5d2621e22deb08207ca1 to your computer and use it in GitHub Desktop.
Simple Python stack
class Stack:
def __init__(self):
self.items=[]
def isEmpty(self):
return self.items==[]
def push(self,item):
self.items.append(item)
def pop(self):
return self.items.pop() if not self.isEmpty() else None
def peek(self):
return self.items[len(self.items) - 1] if not self.isEmpty() else None
def size(self):
return len(self.items)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment