码迷,mamicode.com
首页 > 编程语言 > 详细

python栈

时间:2018-10-08 18:12:37      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:pytho   clear   error   div   push   ror   sel   ack   else   

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栈

标签:pytho   clear   error   div   push   ror   sel   ack   else   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!