当前位置:网站首页>一个栈的输入序列为1 2 3 4 5 的出站顺序的理解
一个栈的输入序列为1 2 3 4 5 的出站顺序的理解
2022-08-05 10:04:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
一个栈的输入序列为1 2 3 4 5 的出站顺序是什么?这个经常会在面试的时候出现。
如何判断栈的进出问题一个栈的输入序列为1 2 3 4 5,则下列序列中不可能是栈的输出序列的是( )A. 2 3 4 1
解答:
一个栈的输入序列为1 2 3 4 5,则下列序列中不可能是栈的输出序列的是( ) A.2 3 4 1 5 B.5 4 1 3 2C.2 3 1 4 5 D.1 5 4 3 2 这题就选B 这样的题做多了就找出规律了 先进1和2,2出栈进入3,3出栈,进入4,4出栈,1在出栈,5进,5出栈,所以是23415,A对 进1和2,2出栈进入3,3出栈,进入4,在进入5,5出,4在出,就是23145,C对 1进,1出,2345进,然后5432出,就是15432,D对 B是错误,因为5要想出来,就必须五个数都要进栈,那么出来就一种结果是54321,答案是54132所以不对 这种题找规律,就能做出来
我们都知道栈是先进后出的,可以理解为桶状结构,
对于上面那种不可能的情况可按下图理解:
5最先出来说明其他的四个都没有出来,那么这四个的顺序就必须安照进来的先后顺序依次排列,这就要符合先进后出的原理,出来只有一个通道,下面的数字必须在后面才能出来。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/106134.html原文链接:https://javaforall.cn
边栏推荐
- 5.部署web项目到云服务器
- After Keil upgrades to AC6, what changes?
- 【zeno】为zeno增加子模块/新节点的最小化的例子
- Technical dry goods | Hausdorff distance for image segmentation based on MindSpore
- 你最隐秘的性格在哪?
- uniapp 连接ibeacon
- hcip BGP 增强实验
- Pytorch Deep Learning Quick Start Tutorial -- Mound Tutorial Notes (3)
- JS逆向入门学习之回收商网,手机号码简易加密解析
- 静态链接和动态链接
猜你喜欢

【 temperature warning program DE development 】 event driven model instance

egg框架使用(一)

Tanabata romantic date without overtime, RPA robot helps you get the job done

【MindSpore Easy-Diantong Robot-01】You may have seen many knowledge quiz robots, but this one is a bit different

IDEA performs the Test operation, resulting in duplicate data when data is inserted

【AGC】增长服务1-远程配置示例

three物体围绕一周呈球形排列

电竞、便捷、高效、安全,盘点OriginOS功能的关键词
![[强网杯2022]WP-UM](/img/3d/caeab05ddca278af274dbf6e2f8ba1.png)
[强网杯2022]WP-UM

High-quality DeFi application building guide to help developers enjoy DeFi Summer
随机推荐
QSS 选择器
[Unity] [UGUI] [Display text on the screen]
MySQL事务
Pycharm 常用外部工具
开发常用手册链接分享
电竞、便捷、高效、安全,盘点OriginOS功能的关键词
After Keil upgrades to AC6, what changes?
IO流篇 -- 基于io流实现文件夹拷贝(拷贝子文件夹及子文件夹内文件)满满的干货
什么是CRM决策分析管理?
歌词整理
Science bosses say | Hong Kong rhubarb KaiBin teacher take you unlock the relationship between the matrix and 6 g
NowCoderTOP35-40 - continuous update ing
2022 Huashu Cup Mathematical Modeling Question A Optimization Design Ideas for Ring Oscillators Code Sharing
DFINITY 基金会创始人谈熊市沉浮,DeFi 项目该何去何从
无题二
Seata source code analysis: initialization process of TM RM client
一文道清什么是SPL
three objects are arranged in a spherical shape around the circumference
PAT Class B-B1019 Digital Black Hole (20)
韦东山 数码相框 项目学习(六)tslib的移植