Python- list structure using stack data structure

class Stack (Object):
     "" " 
    Use stack list to achieve 
    " "" 
    DEF  the __init__ (Self): 
        self.stack = [] 

    DEF Push (Self, Element):
         "" " 
        additive element onto the stack 
        : param Element: 
        : return: 
        "" " 
        self.stack.append (element) 

    DEF POP (Self):
         " "" 
        remove elements from the stack 
        : return: 
        "" " 
        return self.stack.pop () 

    DEF get_top (Self):
         " "" 
        Get stack elements 
        : return: 
        """
        if len(self.stack) > 0:
            return self.stack[-1]
        else:
            return


stack = Stack()
stack.push(1)
stack.push(2)
stack.push(3)
print(stack.stack)
print(stack.pop())
print(stack.get_top())

 

Guess you like

Origin www.cnblogs.com/zivli/p/11234737.html