Link to module Stack

kzagradskiy kzagradskiy at gmail.com
Sat Jan 9 04:07:39 EST 2010


Link to module Stack:
http://groups.google.com/group/comp.lang.python/browse_thread/thread/e6a0668bb2be9a8e/64cb44a120baeca2?lnk=gst&q=stack+module#64cb44a120baeca2

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 = []



More information about the Python-list mailing list