当前位置:网站首页>一个栈的输入序列为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
边栏推荐
- Imitation SBUS fixed with serial data conversion
- IO流篇 -- 基于io流实现文件夹拷贝(拷贝子文件夹及子文件夹内文件)满满的干货
- Custom filters and interceptors implement ThreadLocal thread closure
- 为什么sys_class 里显示的很多表的 RELTABLESPACE 值为 0 ?
- 企业的数字化转型到底是否可以买来?
- 正则表达式replaceFirst()方法具有什么功能呢?
- Brief Analysis of WSGI Protocol
- Jenkins manual (2) - software configuration
- 气象数据数据处理实例——matlab字符串切割匹配与R语言日期匹配(数据拼接)
- What is the function of the regular expression replaceAll() method?
猜你喜欢

MySQL advanced (twenty-seven) database index principle

hcip BGP enhancement experiment

Redis源码解析:Redis Cluster

High-quality DeFi application building guide to help developers enjoy DeFi Summer

2022 Huashu Cup Mathematical Modeling Question A Optimization Design Ideas for Ring Oscillators Code Sharing

Dry goods!Generative Model Evaluation and Diagnosis

Our Web3 Entrepreneurship Project, Yellow

MySQL事务

The JVM collection that Alibaba's top architects have summarized for many years, where can't I check it!

基于MindSpore高效完成图像分割,实现Dice!
随机推荐
告白数字化转型时代:麦聪软件以最简单的方式让企业把数据用起来
Custom filters and interceptors implement ThreadLocal thread closure
How to realize the short press and long press detection of the button?
【Unity】【UGUI】【在屏幕上显示文本】
[强网杯2022]WP-UM
Imitation SBUS fixed with serial data conversion
【Office】Microsoft Office下载地址合集(微软官方原版离线安装下载)
STM32+ULN2003驱动28BYJ4步进电机(根据圈数正转、反转)
Seata source code analysis: initialization process of TM RM client
hcip BGP enhancement experiment
Bias lock/light lock/heavy lock lock is healthier. How is locking and unlocking accomplished?
皕杰报表的下拉框联动
MySQL之数据视图
茄子科技CEO仇俊:以用户为中心,做用户真正需要的产品
What is the function of the regular expression replaceAll() method?
Egg framework usage (2)
Introduction to SD NAND Flash!
Analysis and practice of antjian webshell dynamic encrypted connection
First Decentralized Heist?Loss of nearly 200 million US dollars: analysis of the attack on the cross-chain bridge Nomad
【MindSpore易点通机器人-01】你也许见过很多知识问答机器人,但这个有点不一样