<pre><code>class stack(object):
def __init__(self, maxsize = None):
self.stackArrayList = [] #You can use list to implement the stack
self.maxsize = maxsize
def isEmpty(self):
return self.size() == 0 #Checks if the stackArrayList is Empty.
def push(self, item):
if len(self.stackArrayList) >= self.maxsize:
raise Exception("Stack is Full")
return self.stackArrayList.append(item) #Append new element to the stackArrayList.
def pop(self):
if self.isEmpty():
raise Exception("Stack empty!")
return self.stackArrayList.pop()#Pop and return the top element of the stackArrayList.
def peek(self):
if self.isEmpty():
raise Exception("Stack empty!")
return self.stackArrayList[-1] #Returns the value of top element in the stackArrayList
def size(self):
return len(self.stackArrayList) #Returns the size of stackArrayList
def show(self):
return self.stackArrayList #Returns the contents of the stackArrayList
if __name__ == "__main__":
# Please note that your input is a tuple
data = ("a","b","c","d","e","f","g")
stackArray = stack(maxsize = 7)
for var in data:
stackArray.push(var)
print(stackArray.pop())
print(stackArray.show())
</code></pre>