当前位置:网站首页>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 .
边栏推荐
猜你喜欢
随机推荐
Flutter Widget : KeyedSubtree
Php Export word method (One MHT)
PHP export word method (one MHT)
安装electron失败的解决办法
Qt OpenGL 纹理贴图
Go language to realize static server
Basic knowledge of OpenGL (sort it out according to your own understanding)
ArcGIS application (XXI) ArcMap method of deleting layer specified features
Groovy测试类 和 Junit测试
牛牛的组队竞赛
typeScript
Groovy test class and JUnit test
(construction notes) grasp learning experience
ES6 standard
Dynamically monitor disk i/o with ZABBIX
为什么我的mysql容器启动不了呢
利用Zabbix动态监控磁盘I/O
Vulnhub geminiinc
Qt+vtk+occt reading iges/step model
Dart: about grpc (I)