I was trying to implement Stack via array using Python. Here is my code.
class Stack:
def init(self,top,size):
self.size = 4
self.top = []
def isEmpty(self):
if len(self.top) == 0:
return True
else:
return False
def length(self):
return len(self.top)
def peek(self):
if self.Empty() == True :
print("Cannot peek at an empty Stack")
else:
return self.size[len(self.top)]
def pop(self):
if self.isEmpty():
print("Cannot peek at an empty Stack")
else:
value = self.size[len(self.top)-1]
del self.top[len(self.data) - 1]
return value
def push(self, item):
if len(self.top) >= self.size:
print("Cannot push. Stack is full")
else:
self.top.append(item)
s = Stack()
Whenever I try to use operations such as push, pop etc.. I get an error saying 'Stack object has no attribute top.