Python Learning data Structure Instance code

Source: Internet
Author: User
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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.