首页 > 编程语言 > 详细

python栈

时间:2018-10-08 17:51:16      阅读:139      评论:0      收藏:0      [点我收藏+]
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

 

python栈

原文:https://www.cnblogs.com/tcpblog/p/9755582.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!