ASD/stack.py
2018-01-23 17:57:53 +01:00

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