当前位置:网站首页>两个栈实现一个队列(图解最简单版)
两个栈实现一个队列(图解最简单版)
2022-08-07 23:02:00 【挣脱那枷锁】

import java.util.Stack;
//两个栈实现一个 队列,想象以下是一个队列
public class StackQuene {
private Stack<Integer> stack1=new Stack<>(); //作为入队类
private Stack<Integer> stack2=new Stack<>(); //作为出队列
public void push(int node)
{
stack1.push(node);
}
public int pop()
{
if(stack2.isEmpty()) //只有当stack2为空时,才可以对stack2入栈
{
while(!stack1.isEmpty())
{
stack2.push(stack1.pop());
}
}
return stack2.pop();
}
}边栏推荐
- pinia详解
- Unity editor extension -- custom Window extension
- 详解中断系统
- 我做了一个在线白板(二)
- D. Tournament Countdown(交互题)
- Rest风格操作
- 用户信息管理系统项目测试
- [Students' personal web design works] Use HMTL to make a super beautiful web page for protecting dolphins
- 2022-08-07:以下go语言代码输出什么?A:1 1;B:3 1;C:0 3;D:不能编译。 package main import ( “fmt“ “math“ ) func main
- 论文翻译:2021_LACOPE: Latency-Constrained Pitch Estimation for Speech Enhancement
猜你喜欢

Matlab 在3D 视觉的应用 01 显示PCD点云

Projecting Your View Attentively: Monocular Road Scene Layout Estimation via Cross-view Transformati

流式计算中的 Window 计算

Unity编辑器拓展--Scene视图自定义拓展

Google and universities released the end-to-end panoramic segmentation method MaX-DeepLab, which greatly reduces the artifacts of image segmentation and does not contain manual modules

2022年制冷与空调设备运行操作操作证考试题库模拟考试平台操作

The generation process of Presto Stage

Unity编辑器拓展--Inspector拓展

(二)音视频:MediaCodec编码桌面信息 完整Demo 进一步理解H264

【云原生--Kubernetes】PV、PVC
随机推荐
Rebate 200, the number of islands
pinia详解
Shell:循环语句与函数
Mongodb出现Error: couldn‘t add user: Could not find role: [email protected] 解决方法
Force Buckle Records: Sword Point Offer (3) - JZ24-32
Unity editor extension--custom shortcut key extension
dart method and property privatization
基于消息中间件开发的优点
乡愁
"Experimental Details" to realize the function interpretation in nucleus sampling
【636. 函数的独占时间】
"Latest Open Source Plug and Play" SAM Self-Enhanced Attention Depth Interpretation and Practice (with code and analysis)
【Untitled】
云服务器中mongodb配置账号密码 图文讲解(全)
dart 方法与属性私有化
Locust 之 User
亲测解决:warning ....No license field 问题
Unity editor extension - preview window extension
流式计算中的 Window 计算
普通人可以开户炒股吗?开户安全吗