Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

stack module for py4th

110 views
Skip to first unread message

Nick Seidenman

unread,
Dec 7, 1994, 11:35:31 AM12/7/94
to
Here's the stack module for py4th.

nick

---------------<cut here>----------------
#!/usr/Util/bin/python
#
# @(#)stack.py 1.1
#
# stack.py
# generic stack class.

class Stack:
def __init__(self):
self.__heap = []

def push (self, word):
self.__heap.append (word)

def pop (self):
if len(self.__heap) == 0:
raise InnerInterpreterError, "stack underflow"

result = self.__heap[-1]
del self.__heap[-1]
return result

def __repr__(self):
return `self.__heap`

def __str__(self):
return `self.__heap`

def flush (self):
self.__heap = []

0 new messages