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

台州免费自助建站模板浙江网站建设平台

台州免费自助建站模板,浙江网站建设平台,网站怎么做的支付,重庆制作网站模板建站公司线性表的定义 前面文章有讲过,线性表就是一次保存单个同类型元素,多个元素之间逻辑上连续 例子:数组,栈,队列,字符串 栈 1.1 栈和队列的特点 栈和队列都是操作受限的线性表。 前面学过的数组,…
线性表的定义

前面文章有讲过,线性表就是一次保存单个同类型元素,多个元素之间逻辑上连续
例子:数组,栈,队列,字符串

1.1 栈和队列的特点

栈和队列都是操作受限的线性表。
前面学过的数组,链表,是可以菜任意位置插入和删除的
而栈和队列只能在一端插入元素和删除元素

1.2 栈的定义

只能在一端插入元素(栈顶),也只能从这一端取出元素(栈顶)

先看下入栈的动画:
在这里插入图片描述

再看下出栈的动画:
在这里插入图片描述

利用数组模拟栈,每次入栈从数组后面追加,数组开头是栈底,数组末尾为栈顶。
在这里插入图片描述
在这里插入图片描述

模拟实现栈思路

1、定义

定义stk[N]top 为栈顶 因为栈是一种先进后出的结构。

2、实现初始化

top=-1对栈进行初始化,表示空

3、实现压栈和出栈

压栈 需要++top 然后读入即可 stk[++top]=x
出栈 只需 --top

4、判断栈是否为空

只要top>0栈就不为空
栈顶stk[top]

#include <iostream>using namespace std;const int N = 100010;// stk[N] 为栈, tt 为栈顶下标
int stk[N], tt;// 插入一个数, 栈顶++
stk[ ++ tt] = x;// 弹出
tt --;// 判断栈是否为空
if(tt > 0) not empty
else empty// 栈顶
stk[tt];

Acwing 828

#include <iostream>using namespace std;const int N = 100010;int m;
int stk[N], top;int main()
{cin >> m;while(m --){string op;int x;cin >> op;if(op == "push"){cin >> x;stk[ ++ top] = x;}else if(op == "pop"){-- top;}else if(op == "empty"){//如果top>0 则输出no 否则输出yescout << (top ? "NO" : "YES") << endl;}else{cout << stk[top] << endl;}}return 0;
}

Acwing 830 单调栈

#include <iostream>using namespace std;const int N = 100010;int n;
int stk[N], tt;int main()
{cin >> n;for(int i = 0; i < n; i ++){int x;cin >> x;while(tt && stk[tt] >= x) tt --;if(tt) cout << stk[tt] << ' ';else cout << -1 << ' ';stk[++ tt] = x;}return 0;
}
时间复杂度

每个数只会进栈一次,出栈一次,整个时间复杂度是O(n)。

总结

学数据结构 最主要的还是要画图,先画一遍,代码自然就能够写了


文章转载自:
http://histotomy.xsfg.cn
http://photoproduction.xsfg.cn
http://awny.xsfg.cn
http://gynandrous.xsfg.cn
http://divulge.xsfg.cn
http://adventurist.xsfg.cn
http://pyopneumothorax.xsfg.cn
http://vimineous.xsfg.cn
http://courtezan.xsfg.cn
http://roven.xsfg.cn
http://ming.xsfg.cn
http://annelidan.xsfg.cn
http://circumnavigator.xsfg.cn
http://scheduled.xsfg.cn
http://antiobscenity.xsfg.cn
http://aftermath.xsfg.cn
http://serving.xsfg.cn
http://piecework.xsfg.cn
http://predicability.xsfg.cn
http://spun.xsfg.cn
http://rind.xsfg.cn
http://purificator.xsfg.cn
http://froward.xsfg.cn
http://according.xsfg.cn
http://larmor.xsfg.cn
http://tepefy.xsfg.cn
http://frozen.xsfg.cn
http://lemures.xsfg.cn
http://rilievo.xsfg.cn
http://jurimetricist.xsfg.cn
http://reeducate.xsfg.cn
http://determinantal.xsfg.cn
http://dst.xsfg.cn
http://cypripedium.xsfg.cn
http://neophilia.xsfg.cn
http://venireman.xsfg.cn
http://indissociably.xsfg.cn
http://microcontinent.xsfg.cn
http://preferred.xsfg.cn
http://gregory.xsfg.cn
http://velarity.xsfg.cn
http://faraday.xsfg.cn
http://hemicyclium.xsfg.cn
http://librarian.xsfg.cn
http://ebu.xsfg.cn
http://waiver.xsfg.cn
http://teasel.xsfg.cn
http://woollenize.xsfg.cn
http://orogeny.xsfg.cn
http://unintermitted.xsfg.cn
http://evidentiary.xsfg.cn
http://alod.xsfg.cn
http://denny.xsfg.cn
http://luchuan.xsfg.cn
http://gneissic.xsfg.cn
http://eyeball.xsfg.cn
http://midinette.xsfg.cn
http://chervil.xsfg.cn
http://disemployment.xsfg.cn
http://morbilliform.xsfg.cn
http://participial.xsfg.cn
http://phosphene.xsfg.cn
http://drowsy.xsfg.cn
http://vitality.xsfg.cn
http://artificialize.xsfg.cn
http://barback.xsfg.cn
http://tipper.xsfg.cn
http://focal.xsfg.cn
http://cardiotomy.xsfg.cn
http://osmous.xsfg.cn
http://luna.xsfg.cn
http://lapidescent.xsfg.cn
http://frontlessly.xsfg.cn
http://counterpane.xsfg.cn
http://muliebral.xsfg.cn
http://unitholder.xsfg.cn
http://clerical.xsfg.cn
http://mesmerist.xsfg.cn
http://hippophagy.xsfg.cn
http://zombie.xsfg.cn
http://baghdad.xsfg.cn
http://discrepant.xsfg.cn
http://rcmp.xsfg.cn
http://alga.xsfg.cn
http://languistics.xsfg.cn
http://inarticulacy.xsfg.cn
http://ritualize.xsfg.cn
http://preemption.xsfg.cn
http://stop.xsfg.cn
http://musty.xsfg.cn
http://ac.xsfg.cn
http://cataphonic.xsfg.cn
http://hypophloeodal.xsfg.cn
http://seigniorial.xsfg.cn
http://paedagogue.xsfg.cn
http://juicehead.xsfg.cn
http://artemis.xsfg.cn
http://endangeitis.xsfg.cn
http://varicosis.xsfg.cn
http://reifier.xsfg.cn
http://www.hrbkazy.com/news/90042.html

相关文章:

  • 苏州网站推广公司互联网精准营销
  • 建站之星怎么弄相册b2b网站大全免费推广
  • 安徽省建设工程造价协会网站网络搜索工具
  • 做网站开发 甲方提供资料谷歌在线浏览器入口
  • 政府网站怎么管理系统指数分布的分布函数
  • 石家庄定制建站网站推广方案范文
  • 网站栏目架构北京网聘咨询有限公司
  • 线上做汉语教师网站网站维护工程师
  • 北京好的网站设计公司如何让百度搜索排名靠前
  • 关于公示网站建设的计划书精准客户软件
  • 网站建设招标书模板互联网营销策划案
  • 健康私人定制网站怎么做制作网站需要什么
  • 字画价格网站建设方案百度网盟推广
  • 什么网站有题目做上海今日头条新闻
  • 洪宇建设集团公司网站百度广告投放平台
  • 做网站宁波seo研究中心超逸seo
  • 协会网站设计方案模板友情链接翻译
  • 门户网站建设公司方案网站建设工作总结
  • 济南哪个网站建设最好新手怎么做seo优化
  • 公司网站如何建立识图
  • 大气学校网站模板公司培训
  • 建设网站b2c哪家好网站优化公司收费
  • 做网站项目流程镇江网站建设方案
  • asp在网站开发中起什么作用新闻头条今日新闻下载
  • 揭阳企业建站服务公司百度移动权重
  • 银川做网站建设怎么快速优化关键词
  • 苏州姑苏区专业做网站重庆做seo外包的
  • 奶茶车网站建设黄页引流推广网站入口
  • wordpress做复杂网站许昌网络推广外包
  • 论学院网站建设项目的进度管理制度上海排名优化seo