• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > python学习数据结构实例代码

python学习数据结构实例代码

作者:hebedich 字体:[增加 减小] 来源:互联网

hebedich 通过本文主要向大家介绍了python学习数据结构实例代码等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

在学习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()
</div>

以上所述就是本文给大家分享的全部内容了,希望大家能够喜欢。

</div>

您可能想查找下面的文章:

相关文章

  • Python使用shelve模块实现简单数据存储的方法
  • Python导出DBF文件到Excel的方法
  • Python实现抓取网页并且解析的实例
  • python使用os模块的os.walk遍历文件夹示例
  • Python常用知识点汇总
  • Python中字典的基本知识初步介绍
  • Python单例模式实例分析
  • python脚本实现统计日志文件中的ip访问次数代码分享
  • Python UnicodeEncodeError: 'gbk' codec can't encode character 解决方法
  • python操作mongodb根据_id查询数据的实现方法

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • Python操作MongoDB数据库PyMongo库使用方法
    • python原始套接字编程示例分享
    • Python中使用PDB库调试程序
    • 编写Python脚本使得web页面上的代码高亮显示
    • 详解python的几种标准输出重定向方式
    • python模块之StringIO使用示例
    • python常规方法实现数组的全排列
    • 玩转python爬虫之URLError异常处理
    • Python中使用bidict模块双向字典结构的奇技淫巧
    • Python logging模块学习笔记

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有