Analog stack python list

Stack class (): 
DEF the __init __ (Self, len):
self.stack = []
self.len len =
DEF __repr __ (Self): # view object properties to facilitate
return str (self.stack) # needs to return a string
def push ( self, element): # push
self.stack.append (Element)
DEF POP (Self): # popped
IF self.stack:
self.stack.pop ()
the else:
return LookupError ( "stack is empty")
DEF is_empty (self): # determine whether the air
return BOOL (self.stack)
DEF full (Self): # determine whether the stack is full
iF len (self.stack) == self.len:
Print ( "full stack")
the else:
Print ( "not full stack")
DEF the Find (Self, element): # find an element position
self.stack.index return (Element)
DEF PEEK (Self): Returns the top element #
IF self.is_empty ():
return self.stack [-1]
the else:
Print ( "empty stack")

S = Stack ( . 4)
Print (s.is_empty ())
s.push (. 4)
s.push (. 6)
s.push ( 'A')
s.full ()
Print (s.peek ())
Print (s.find ( ' A '))
# s.pop ()
Print (S)

Guess you like

Origin www.cnblogs.com/niucunguo/p/11416601.html
Recommended