class ArrayStack(object):
def __init__(self,initsize):
if initsize<0:
raise Exception('wrong')
self.arr = [0 for i in range(initsize)]
self.size = 0
def push(self,item):
if self.size == len(self.arr):
raise Exception('Stack has full')
self.arr[self.size] = item
self.size+=1
return self.arr
def pop1(self):
if self.size == 0:
raise Exception('Stack has empty')
self.arr.pop()
self.size-=1
return self.arr
def peek(self):
if self.size==0:
return None
return self.arr[self.size-1]
if __name__=='__main__':
stack = ArrayStack(3)
print(stack)
stack.push(1)
print(stack.arr)
print(stack.peek())
stack.push(2)
print(stack)
stack.push(3)
print(stack)
print(stack.peek())
stack.pop1()