25.简单实现一个stack

class Stack:
    def __init__(self):
        self.items = []
    def __iter__(self):
        return self.items.__iter__()
    def pop(self):
        return self.items.pop()
    def top(self):
        if len(self.items) > 0:
            return self.items[len(self.items) - 1]
    def push(self, item):
        self.items.append(item)
    def empty(self):
        self.items = []
    def size(self):
        return len(self.items)

你可能感兴趣的:(25.简单实现一个stack)