我想用Python实现一个简单的Python堆栈。我想知道如果有人能让我知道我的代码有什么问题。用Python实现堆栈
class myStack:
def __init__(self):
self = []
def isEmpty(self):
return self == []
def push(self, item):
self.append(item)
def pop(self):
return self.pop(0)
def size(self):
return len(self)
s = myStack()
s.push('1')
s.push('2')
print(s.pop())
print s
http://docs.python.org/2/tutorial/datastructures。html#使用列表作为堆栈 –
即使您的代码设法将您的对象变为列表,这是否意味着您将释放所有自定义方法? –
它应该只是pop()不弹出(0)。 pop(0)使它成为队列。 – Aravind