In the process of learning Python, it is used to practice the code, and review the data structure
#coding: Utf-8#author:elvis class Stack (object): Def __init__ (self, size=8): Self.stack = [] self.size = Size Self.top =-1 def is_empty (self): if self.top = = -1:return True else:return False def is_full (self): if self.top +1 = = Self.size:return True else:return False def push (self, data): If Self.is_full (): Raise Exception (' StackOverflow ') else:self.top + = 1 self.stack.append (data) def Stack_pop (self): if Self.is_empty (): Raise Exception (' Stackisempty ') else:self.top-= 1 return self . Stack.pop () def stack_top (self): if Self.is_empty (): Raise Exception (' Stackisempty ') Else:return self . Stack[self.top] def show (self): print self.stack stack = stack () stack.push (1) stack.push (2) Stack.push (' A ') Stack.push ( ' B ') Stack.push (5) Stack.push (6) Stack.stack_pop () Stack.stack_pop () Stack.stack_top () Stack.is_empty () stack.is_full () stack.show ()
The above mentioned is this article to share all the content, I hope you can enjoy.