当前位置:网站首页>232. Implement queue with stack
232. Implement queue with stack
2022-07-03 12:11:00 【zwanying】
- Using stack to realize queue
Please use only two stacks to implement the FIFO queue . The queue should support all operations supported by the general queue (push、pop、peek、empty):
Push : Simulate queuing
Out of the stack : Simulate the queue
push: Append an element after the queue
pop: Delete the first element of the queue
peek: Get the first element of the queue
Be careful :
1、 Initialize two stacks , Must be outside the method , It's a class variable .
2、 Outgoing queue , When you move elements from in stack to out stack , You must ensure that there are no elements in the stack , otherwise , When adding an element again , It will cause disorder .
边栏推荐
猜你喜欢
随机推荐
Wrong arrangement (lottery, email)
[MySQL special] read lock and write lock
PHP export word method (phpword)
网络通讯之Socket-Tcp(一)
vulnhub之Ripper
New features of ES6
Talk about the state management mechanism in Flink framework
QT OpenGL rotate, pan, zoom
DNS multi-point deployment IP anycast+bgp actual combat analysis
laravel 时区问题timezone
vulnhub之momentum
Xiaopeng P7 hit the guardrail and the airbag did not pop up. The official responded that the impact strength did not meet the ejection requirements
Vulnhub pyexp
typeScript
Shutter: add gradient stroke to font
Vulnhub narak
Dart: About zone
Php Export word method (One MHT)
Solutions to the failure of installing electron
Redis 笔记 01:入门篇







![[official MySQL document] deadlock](/img/2d/04e97d696f20c2524701888ea9cd10.png)
