22 lines
483 B
Python
22 lines
483 B
Python
class Stack:
|
|
class StackElem:
|
|
def __init__(self, elt, prec):
|
|
self.elt = elt
|
|
self.prec = prec
|
|
|
|
def __init__(self, elts=[]):
|
|
self.first = None
|
|
for e in elts:
|
|
self.add(e)
|
|
|
|
def add(self, e):
|
|
se = self.StackElem(e, self.first)
|
|
self.first = se
|
|
|
|
def pop(self):
|
|
e = self.first.elt
|
|
self.first = self.first.prec
|
|
return e
|
|
|
|
def empty(self):
|
|
return self.first is None
|