python学习数据结构实例代码,python数据结构实例
python学习数据结构实例代码,python数据结构实例
在学习python的过程中,用来练习代码,并且复习数据结构的
#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()
以上所述就是本文给大家分享的全部内容了,希望大家能够喜欢。
相关内容
- Python使用MONGODB入门实例,pythonmongodb实例
- Python中IPYTHON入门实例,pythonipython入门
- Python素数检测的方法,python素数检测
- 详解Python的Django框架中的templates设置,djangotemplates
- 从Python的源码来解析Python下的freeblock,pythonfreeblock
- 详细解析Python中__init__()方法的高级应用,python__init__
- 深入解析Python中的WSGI接口,解析pythonwsgi接口
- python引用DLL文件的方法,
- python自定义解析简单xml格式文件的方法,pythonxml
- python处理图片之PIL模块简单使用方法,
评论关闭