Created
February 24, 2018 21:08
-
-
Save Mahdisadjadi/bce6b7f2304ca87a623414f7489e3dd4 to your computer and use it in GitHub Desktop.
A simple implementation of Stack data structure in python
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
# 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