当前位置: 首页 > news >正文

江西中慧城乡建设开发公司网站阜新建设网站

江西中慧城乡建设开发公司网站,阜新建设网站,怎么用ps做静态网站,苏州做网站设计数据结构链表之栈 栈的概述 定义#xff1a;栈是一种基于先进后出(FILO)的数据结构#xff0c;是一种只能在一段进行插入和删除操作的特殊线性表。引入名词#xff1a;将数据存入栈的动作称为压栈#xff0c;将数据取出栈的动作称为弹栈栈的特点#xff1a;先进入栈的元…数据结构链表之栈 栈的概述 定义栈是一种基于先进后出(FILO)的数据结构是一种只能在一段进行插入和删除操作的特殊线性表。引入名词将数据存入栈的动作称为压栈将数据取出栈的动作称为弹栈栈的特点先进入栈的元素会被压入栈底最后一位元素所处的位置就是栈顶弹栈时最后一个元素最先被读取依次往下取出因此叫做First In Last Out 栈可以用顺序表(python中列表)实现也可以用链表实现这里实现的方式的是使用链表有兴趣的同学可以自己编写代码用列表实现栈 python代码实现 class Node:def __init__(self, item):self.item itemself.next Noneclass Stack:def __init__(self):self.head Noneself.len 0def is_empty(self):return not self.len# def length(self):# return self.lendef push(self, item):Push an element into the stacknode Node(item)node.next self.headself.head nodeself.len 1def pop(self):Pop a value from the stack top# if not self.head:# raise IndexError(pop from empty list)cur self.headif self.head:self.head self.head.nextself.len - 1return cur# Make the Stack iterabledef __iter__(self):self.cur self.head# if not self.cur:# raise StopIteration # The error here will be raised if the condition were reachedreturn selfdef __next__(self):if not self.cur:raise StopIteration # The error here actually wont be raisedtry:temp self.curself.cur self.cur.nextreturn tempexcept AttributeError as e:raise StopIteration主要实现的功能 is_empty()判断栈是否为空length()同len属性可以返回栈的长度push()向栈压入元素pop()从栈顶取出一个元素重写的__iter__()和__next__()用于实现栈的遍历功能 功能验证 if __name__ __main__:stack Stack()print(fIs empty? {stack.is_empty()})print(Push elements into the stack:)stack.push(a)stack.push(b)stack.push(c)stack.push(d)# Iterate the stackfor item in stack:print(item.item, end )print(f\nPop a value from the top stack: {stack.pop().item})print(fThe number(length) of the remanent nodes is: {stack.len})输出结果 Is empty? True Push elements into the stack: d c b a Pop a value from the top stack: d The number(length) of the remanent nodes is: 3
http://www.pierceye.com/news/662784/

相关文章:

  • 建站公司学习筑梦网站建设
  • 手工艺品网站建设侧胡顺个人简历表格可填写
  • 电商网站竞价推广策略淘宝做问卷的网站
  • 门窗 东莞网站建设婚庆公司收费标准
  • 网站页面下沉的特效代码网络建设存在的问题
  • 给网站做维护是什么工作网页怎么赚钱
  • 三丰云做游戏网站win主机安装wordpress
  • 网站建设黄荣vuejs做视频网站设计
  • 手机怎样下载安装建设银行网站企业通过网络推广成功的案例
  • 门户网站开发工具软件哪个公司的网络最好用
  • 河南省住房和城乡建设厅查询网站首页舆情网站推荐
  • 网页设计是网站建设与管理的内容吗公司网络营销的方案思路
  • 商业授权网站标题优化技巧
  • 班级网站做哪些方面阿里云市场网站建设
  • 2345网站登录电子工程师有前途吗
  • 网站建设企业邮箱制作网站山东平台网站建设制作
  • 仿新浪微博网站代码国家高新技术企业公示
  • 遵义网站建设公司电话多少成都网站优化seo
  • 宝安网站设计排名网站建设收费标准资讯
  • 景安怎么把网站做别名西安网站优化seo
  • 长沙专业网站建设怎么做云南昆明百度推广公司
  • 网页制作网站的大作业网站开发怎么设置打印按钮
  • 金乡网站建设哪家便宜建网站解决方案
  • 大港油田建设官方网站怎么帮人做网站
  • nginx建设网站教程wordpress文章列表格子
  • 山东网站开发学校深圳福田网站建设公司
  • 做电商网站的框架结构图江西省住房和城乡建设厅
  • 运输网站建设网站上的销售怎么做的
  • ps做网站首页效果图潮安区住房和城乡建设局网站
  • 商业网站怎么做做图赚钱的网站