[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/OmkarPathak/pygorithm/master/pygorithm/data_structures/stack.py [Back]  [Original]

"""
Author: OMKAR PATHAK
Created On: 3rd August 2017
"""
from string import ascii_letters
import inspect


class Stack(object):
    """
    Stack object
    """
    def __init__(self, limit=10):
        """
        :param limit: the stack size
        """
        self.stack = []
        self.limit = limit

    def __str__(self):
        return ' '.join([str(i) for i in self.stack])

    def push(self, data):
        """
        pushes an item into the stack
        returns -1 if the stack is empty
        """
        if len(self.stack) >= self.limit:
            # indicates stack overflow
            return -1       
        else:
            self.stack.append(data)

    def pop(self):
        """
        pops the topmost item from the stack
        returns -1 if the stack is empty
        """
        if len(self.stack) 

Web Proxy Viewer  |  New URL  |  Original Page