当前位置:网站首页>Sorting from one stack to another
Sorting from one stack to another
2022-06-28 04:06:00 【The roaring Conan】
Using one stack to sort another stack
【 subject 】
The type of an element in a stack is integer , Now I want to sort the stack from top to bottom in the order of big to small , Only one stack is allowed . besides , You can apply for new variables , But you can't apply for additional data structures . How to sort ?
【 Ideas 】
Stack to sort :stackData, Use an auxiliary stack :stackHelp
from stackData Start pop, Record as cur, that cur and stackHelp The top of the stack is relatively , If stackHelp Stack top ratio of cur Small , Just put stackHelp The stack data goes all the way stackData Pressure , Know that the conditions are not tenable (stackHelp.peek()<cur), The premise must be stackHelp Not empty , And then cur Push the stackHelp in , A phenomenon can be seen under the simulation ,stackHelp The bottom of the stack is always large , And then smaller up , Last stackHelp It becomes from the top of the stack to the bottom of the stack , The data is getting bigger , Finally, put stackHelp Data pop-up and push in stackData, That's it , And that's what happened stackData Stack from top to bottom, from big to small .
【 Code 】
package pers.keafmd.accumulate.codeinterviewguide边栏推荐
- 11_刻意练习精讲
- How to write a software test report? Here comes the third party performance report template
- Several ways of sharing printers in LAN
- 单一职责原则
- 测不准原理
- MSc 307 (88) (2010 FTPC code) Part 9 bedding test
- Analyzing the comprehensive application ability of educational robot
- MySQL master-slave replication, separation and resolution
- 软件测试报告怎么编写?第三方性能报告范文模板来了
- English语法_形容词/副词3级 - 比较级
猜你喜欢
随机推荐
03 MongoDB文档的各种增加、更新、删除操作总结
How to learn a programming language systematically| Dark horse programmer
A Preliminary Study of Blackbody radiation
光伏板怎么申请ASTM E108阻燃测试?
vscode中出现无法在只读编辑器中编辑
[graduation season] graduate summary
Open the field of maker education and creation
ERP升级的另一种选择,MES系统
English grammar_ Adjective / adverb Level 3 - Comparative_ Useful Expressions
品达通用权限系统(Day 5~Day 6)
applicationContext.getBeansOfType 获取一个接口下所有实现类 执行方法或者获取实现类对象等 操作应用场景学习总结
软件测试报告怎么编写?第三方性能报告范文模板来了
Chapter 14 AC-DC power supply front stage circuit note I
How to apply for ASTM E108 flame retardant test for photovoltaic panels?
美创入选“2022 CCIA中国网络安全竞争力50强”榜单
Particle theory of light (photoelectric effect / Compton effect)
加法器—笔记
Elk builds log analysis system + Zipkin service link tracking integration
Unity C# 网络学习(十一)——自定义协议生成工具
One article tells you what kubernetes is








