stack.py

'''

实现语言: Python
有次序的数据集, 每个数据项仅从栈顶一端加入和移除
'''

class Stack:
def __init__(self):
self.items = []

def isEmpty(self):
return self.items == []

def push(self, item):
self.items.append(item)

def pop(self):
return self.items.pop()

# Peek 偷看;一瞥,看一眼;(计算机)读取数据
def peek(self):
return self.items[len(self.items) - 1]

def size(self):
return len(self.items)