python栈

class StackEmptyError(Exception):    pass class StackFullError(Exception):    pass class Stack:    def __init__(self, size):        self.index = 0        self.size = size        self.lst = []       def pop(self):        if self.index > 0:            ret = self.lst[self.index]            return ret        else:            raise StackEmptyError("stack has already empty")       def push(self, el):        if self.index > self.size:            raise StackFullError("stack is full")        else:            self.lst[self.index] = el            self.index = self.index + 1       def clear(self):        self.lst.clear()        self.index = 0           def __sizeof__(self):        return len(self.lst)               def max(self):        return self.size       def now(self):        return self.index

 

posted @ 2018-10-08 17:19  python传言  阅读(130)  评论(0编辑  收藏  举报