Skip to content

Instantly share code, notes, and snippets.

@Mahdisadjadi
Created February 24, 2018 21:08
Show Gist options
  • Save Mahdisadjadi/bce6b7f2304ca87a623414f7489e3dd4 to your computer and use it in GitHub Desktop.
Save Mahdisadjadi/bce6b7f2304ca87a623414f7489e3dd4 to your computer and use it in GitHub Desktop.
A simple implementation of Stack data structure in python
# A simple implementation of Stack data structure in python
# LIFO: last (item) in, first (item) out
# Insert at the end, pop the front of the list
class Stack():
def __init__(self):
self.items = []
def isEmpty(self):
return self.items == []
def size(self):
# size of the list
return len(self.items)
def push(self, item):
#insert the item in the end of the list
self.items.append(item)
def pop(self):
# removes and returns the last item in the list
return self.items.pop()
def peek(self):
# returns the last item
return self.items[-1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment