Created
July 31, 2017 13:46
-
-
Save dongho-jung/2954b8767a8cb1c12f61619caaf93f0d to your computer and use it in GitHub Desktop.
Stack own implementation..
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
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