当前位置:网站首页>Reverse a stack with recursive functions and stack operations only
Reverse a stack with recursive functions and stack operations only
2022-06-28 04:05:00 【The roaring Conan】
Reverse a stack with recursive functions and stack operations only
【 subject 】
A stack is pushed in turn 1、2、3、4、5, So from the top to the bottom of the stack are 5、4、3、2、1. After transposing this stack , From the top to the bottom of the stack is 1、2、3、4、5, That is to realize the reverse order of the elements in the stack , But it can only be implemented with recursive functions , You can't use other data structures .
【 Ideas 】
Only recursive functions are required , You need to design two functions , Function returns the bottom of the stack element and removes ; Function 2 implements the reverse stack , Function one is required .
explain : The picture comes from Zuoshen's program code interview guide , For learning purposes only .
Function one :
// Return to the bottom of the stack and remove
public static int getAndRemoveLastElement(Stack<Integer> stack)边栏推荐
- MySQL 主从复制、分离解析
- 如何修改SE38编辑器主题
- leetcode:494. All methods of adding and subtracting operators to the array to get the specified value
- 一文告诉你什么是 Kubernetes
- A Preliminary Study of Blackbody radiation
- MSC 307(88) (2010 FTPC Code) Part 9床上用品试验
- Unity C # e-learning (11) -- custom protocol generation tool
- Arrangement of basic electrical knowledge (I)
- 指针链表
- Does the applet input box flash?
猜你喜欢
随机推荐
局域网内共享打印机的几种方式
What is the process of en 1101 flammability test for curtains?
光的粒子说(光电效应/康普顿效应)
Building log analysis system with elk (III) -- Security Authentication
使用信号分析器
A Preliminary Study of Blackbody radiation
Several ways of sharing printers in LAN
Principle and Simulation of switching power supply buck circuit
How to modify a se38 editor theme
一千行 MySQL 学习笔记,值得收藏!
MySQL 主从复制、分离解析
解析教育机器人的综合应用能力
机器学习入门笔记
用一个栈实现另一个栈的排序
基于正点原子stm32的mini板的TFTLCD显示实验
第一章 Bash 入门
《性能之巅第2版》阅读笔记(二)--性能观察工具
Pointer linked list
Cannot edit in read-only editor if it appears in vscode
Staggered and permutation combination formula








