Python中的栈, 一般用列表实现

class Stack(object):

    def __init__(self):
        self.con = []

    # 入栈
    def push(self, i):
        self.con.append(i)

    # 出栈
    def pop(self):
        self.con.pop()


s = Stack()
s.push(1)
s.push(2)
s.push(3)
s.push(4)
s.pop()
s.pop()
s.pop()
print(s.con)
发布了140 篇原创文章 · 获赞 53 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_44291044/article/details/104632841