当前位置:网站首页>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 .
边栏推荐
- Solution to the second weekly test of ACM intensive training of Hunan Institute of technology in 2022
- Qt+vtk+occt reading iges/step model
- (construction notes) learn the specific technology of how to design reusable software entities from three levels: class, API and framework
- 4000字超详解指针
- Dart: About zone
- 安裝electron失敗的解决辦法
- AOSP ~ NTP (Network Time Protocol)
- Itext7 uses iexternalsignature container for signature and signature verification
- 牛牛的组队竞赛
- vulnhub之Nagini
猜你喜欢
随机推荐
Niuniu's team competition
4000 word super detailed pointer
[learning notes] DP status and transfer
Deploying WordPress instance tutorial under coreos
SLF4J 日志门面
Ripper of vulnhub
vulnhub之raven2
MySQL searches and sorts out common methods according to time
Vulnhub pyexp
ES6新特性
vulnhub之presidential
Shutter: overview of shutter architecture (excerpt)
OpenGL shader use
Unicode encoding table download
Groovy测试类 和 Junit测试
抓包整理外篇fiddler———— 会话栏与过滤器[二]
vulnhub之cereal
[MySQL special] read lock and write lock
SystemVerilog -- OOP -- copy of object
Interview experience in summer camp of Central South University in 2022








