Skip to content

Instantly share code, notes, and snippets.

@dongho-jung
Created July 31, 2017 13:46
Show Gist options
  • Save dongho-jung/2954b8767a8cb1c12f61619caaf93f0d to your computer and use it in GitHub Desktop.
Save dongho-jung/2954b8767a8cb1c12f61619caaf93f0d to your computer and use it in GitHub Desktop.
Stack own implementation..
class Stack:
def __init__(self, maximum = 0):
self.__currentIdx = -1
self.__list = list()
self.__maximum = maximum
def push(self, newElement):
if(self.__currentIdx + 1 < self.__maximum or self.__maximum == 0):
self.__currentIdx += 1
self.__list += [newElement]
else:
raise Exception("This stack's maximum is {0}, but current size is {1}".format(self.__maximum, self.__currentIdx + 1))
def pop(self):
if(self.__currentIdx > -1):
res = self.__list[self.__currentIdx]
del self.__list[self.__currentIdx]
self.__currentIdx -= 1
return res
else:
return None
def size(self):
return self.__currentIdx + 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment