class Stack:
"""
Data structure that implements a last-in-first-out (LIFO)
queue policy.
"""
def __init__(self):
self.list = []
def push(self,item):
"""
Push 'item' onto the stack
"""
self.list.append(item)
def pop(self):
"""
Pop the most recently pushed item from
the stack
"""
return self.list.pop()
def isEmpty(self):
"""
Returns true if the stack is empty
"""
return len(self.list) == 0
def top(self):
"""
retrieve the top item
"""
return self.list[-1]
python 栈
最新推荐文章于 2025-06-05 16:21:43 发布