当前位置:网站首页>225. Implement stack with queue
225. Implement stack with queue
2022-07-03 12:11:00 【zwanying】
Please use only two queues to implement one LIFO (LIFO) The stack , And supports all four operations of ordinary stack (push、top、pop and empty).
Realization MyStack class :
void push(int x) Put the element x Press into the top of the stack .
int pop() Remove and return the top element of the stack .
int top() Back to top of stack element .
boolean empty() If the stack is empty , return true ; otherwise , return false .
Review the Java Of Stack and queue .
Stack: One class , Inherit Vector , Thread safety , Poor performance , It is not recommended to use .
push()
pop()
peek()
Queue: An interface , Inherit Collection,LinkedList Inherited the interface .
add offer
remove poll
Element peek
Ideas :
Two queues , A simulation stack , An auxiliary .
push When the elements , Adjust to the order of stacks .
follow-up Get stack top element , Delete stack top element , Don't move .
边栏推荐
- Visual studio 2022 downloading and configuring opencv4.5.5
- SystemVerilog -- OOP -- copy of object
- Notes on 32-96 questions of sword finger offer
- Quantitative calculation research
- Solutions to the failure of installing electron
- Pragma pack syntax and usage
- Unity3d learning notes 5 - create sub mesh
- vulnhub之raven2
- Shutter widget: centerslice attribute
- Symlink(): solution to protocol error in PHP artisan storage:link on win10
猜你喜欢
随机推荐
安裝electron失敗的解决辦法
在CoreOS下部署WordPress实例教程
QT OpenGL rotate, pan, zoom
Vulnhub geminiinc
OpenGL 着色器使用
Dart: about grpc (I)
(数据库提权——Redis)Redis未授权访问漏洞总结
PHP export word method (phpword)
Vulnhub's cereal
Qt+vtk+occt reading iges/step model
How to convert a numeric string to an integer
MySQL searches and sorts out common methods according to time
Dart: About zone
Interview experience in summer camp of Central South University in 2022
Optimize interface performance
During FTP login, the error "530 login incorrect.login failed" is reported
AOSP ~ NTP (Network Time Protocol)
php 获取文件夹下面的文件列表和文件夹列表
Wrong arrangement (lottery, email)
Experience container in libvirt







![[MySQL special] read lock and write lock](/img/ac/e01c26882cc664ea2e5e731c5a8bab.png)
