您的位置:首页 > 文旅 > 旅游 > seo是什么意思新手怎么做seo_河南省最新任命_宁波seo网络推广主要作用_南宁网络推广软件

seo是什么意思新手怎么做seo_河南省最新任命_宁波seo网络推广主要作用_南宁网络推广软件

2025/4/29 14:20:09 来源:https://blog.csdn.net/Fantasydg/article/details/147313265  浏览:    关键词:seo是什么意思新手怎么做seo_河南省最新任命_宁波seo网络推广主要作用_南宁网络推广软件
seo是什么意思新手怎么做seo_河南省最新任命_宁波seo网络推广主要作用_南宁网络推广软件

题号232

请你仅使用两个栈实现先入先出队列。队列应当支持一般队列支持的所有操作(pushpoppeekempty):

class MyQueue {Stack<Integer> stackIn;Stack<Integer> stackOut;/** Initialize your data structure here. */public MyQueue() {stackIn = new Stack<>(); // 负责进栈stackOut = new Stack<>(); // 负责出栈}/** Push element x to the back of queue. */public void push(int x) {stackIn.push(x);}/** Removes the element from in front of queue and returns that element. */public int pop() {    dumpstackIn();return stackOut.pop();}/** Get the front element. */public int peek() {dumpstackIn();return stackOut.peek();}/** Returns whether the queue is empty. */public boolean empty() {return stackIn.isEmpty() && stackOut.isEmpty();}// 如果stackOut为空,那么将stackIn中的元素全部放到stackOut中private void dumpstackIn(){if (!stackOut.isEmpty()) return; while (!stackIn.isEmpty()){stackOut.push(stackIn.pop());}}
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com