当前位置:网站首页>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边栏推荐
猜你喜欢

A solution to the inefficiency of setting debug mode in developing flask framework with pychar

使用tensorboard进行loss可视化

《性能之巅第2版》阅读笔记(二)--CPU监测

leetcode:494.数组中添加加减运算符得到指定值的所有方法

电学基础知识整理(二)

光的粒子说(光电效应/康普顿效应)

KVM常用命令详解

美创数据安全管理平台获信通院“数据安全产品能力验证计划”评测证书

ambari SSLError: Failed to connect. Please check openssl library versions.

机器学习入门笔记
随机推荐
GenICam GenTL 标准 ver1.5(2)
测不准原理
视频爆炸时代,谁在支撑视频生态网高速运行?
仅用递归函数和栈操作逆序一个栈
工业物联网将取代人工发展吗?
《性能之巅第2版》阅读笔记(二)--CPU监测
Analysis of future teacher research ability under steam education framework
@Several scenarios of transactional failure
错排兼排列组合公式
利用ELK 搭建日志分析系统(一)—— 组件介绍
如何系统学习一门编程语言? | 黑马程序员
Pointer linked list
Leetcode: monotonic stack structure (Advanced)
音频 scipy 中 spectrogram 的运作机制
Meichuang data security management platform has obtained the evaluation certificate of "data security product capability verification plan" of the Institute
How the uni app automatically switches the requested address according to the environment
小程序输入框闪动?
PostgreSQL 实现批量更新、删除、插入
Understanding and learning of parental delegation mechanism
领歌leangoo敏捷看板工具新增导出卡片文档和粘贴共享脑图节点功能