# A simple example of a stack

# This file serves mainly as a demonstration of
# the stack idea, implementation and management.

# Python provides a deque module which
# should be used in most standard "real life" applications.
# where a stack is needed.
# For more details on deque module see
# https://docs.python.org/3/library/collections.html?highlight=deque#collections.deque

class Stack:

    def __init__(self):
        self.items = []

    def size(self):
        return len(self.items)

    def isEmpty(self):
        if self.size() == 0:
            return True
        else:
            return False

    def push(self, item):
        self.items.append(item)

    def pop(self):
        if self.isEmpty():
            return None
        top = self.items[-1]
        del( self.items[-1] )
        return top

    def top(self):
        if self.isEmpty():
            return None
        return self.items[-1]


    def display(self):
        if self.size() == 0:
            print("Stack is empty.")
            return
        border = ["+"] + [ ("-"*(2+len(str(it))) + "+") for it in self.items ]
        itstr = [" "+ (str(it)) + " " for it in self.items ]
        print( "".join(border) )
        print( "|" + "|".join(itstr) + "|" )
        print( "".join(border) )

    # some aliases

    def insTop(self, item ):
        self.push( item )

    def delTop(self):
        return self.pop()
        
    def peek(self):
        return self.top()

    # ---- end of class Stack -----------------------



st = Stack()
st.push(10)
st.push(2000)
st.display()
st.push(30)
st.push(140)
st.display()
st.pop()
st.display()
st.pop()
st.display()
st.pop()
st.display()
st.pop()
st.display()





