当前位置:网站首页>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边栏推荐
- English语法_形容词/副词3级 - 比较级
- [graduation season] graduate summary
- 用一个栈实现另一个栈的排序
- 等保三级密码复杂度是多少?多久更换一次?
- Open the field of maker education and creation
- gcd最大公约数
- 2021年终总结及2022年展望
- Principle and Simulation of switching power supply buck circuit
- Meichuang data security management platform has obtained the evaluation certificate of "data security product capability verification plan" of the Institute
- MySQL 主从复制、分离解析
猜你喜欢
随机推荐
Arrangement of basic electrical knowledge (II)
错排兼排列组合公式
小程序image组件不显示图片?
English notes - cause and effect
Chapter 1 Introduction to bash
利用ELK 搭建日志分析系统(一)—— 组件介绍
iptables防火墙规则和firewalld防火墙规则详解
关于 SY8120I 的DC-DC的降压芯片的学习(12V降至3.3V)
Analysis of future teacher research ability under steam education framework
One article tells you what kubernetes is
利用ELK 搭建日志分析系统(二)—— 部署安装
Does the applet input box flash?
05 MongoDB对列的各种操作总结
What is the process of en 1101 flammability test for curtains?
Analyzing the comprehensive application ability of educational robot
Open the field of maker education and creation
第一章 Bash 入门
MSc 307 (88) (2010 FTPC code) Part 9 bedding test
How to write anti shake throttling for small programs?
gcd最大公约数









