请使用堆栈这一个数据结构实现简单FIFO(先入先出)队列,队列要实现两个方法: push、pop。 为自动测试方便,使用每行输入模拟操作: 1) push 1 表明向队列里面新增一个元素 1 , push 和元素之间用空格表示; 2) pop 表明输出当前队列里面的第一个元素,如果当前队列为空请输出null 请将每个输出以英文逗号拼接到一个字符串中。
示例1
输入
["push 1","push 2","pop","pop","pop","push 3"]
输出
"1,2,null"
加载中...
import java.util.*; public class Solution { /** * * @param ops string字符串ArrayList 操作步骤 * @return string字符串 */ public String doQueue (ArrayList
ops) { // write code here } }
class Solution { public: /** * * @param ops string字符串一维数组 操作步骤 * @param opsLen int ops数组长度 * @return string字符串 */ string doQueue(string* ops, int opsLen) { // write code here } };
# # # @param ops string字符串一维数组 操作步骤 # @return string字符串 # class Solution: def doQueue(self , ops ): # write code here
/** * * @param ops string字符串一维数组 操作步骤 * @return string字符串 */ function doQueue( ops ) { // write code here } module.exports = { doQueue : doQueue };
# # # @param ops string字符串一维数组 操作步骤 # @return string字符串 # class Solution: def doQueue(self , ops ): # write code here
package main /** * * @param ops string字符串一维数组 操作步骤 * @return string字符串 */ func doQueue( ops []string ) string { // write code here }
/** * * @param ops string字符串一维数组 操作步骤 * @param opsLen int ops数组长度 * @return string字符串 */ char* doQueue(char** ops, int opsLen ) { // write code here }
["push 1","push 2","pop","pop","pop","push 3"]
"1,2,null"