题解 | #【模板】循环队列#

【模板】循环队列

https://www.nowcoder.com/practice/0a3a216e50004d8bb5da43ad38bcfcbf

const readline = require("readline");

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});
let len: number = 1;
let arr:string[] = [];
rl.on("line", function (line) {
    const tokens = line.split(" ");
    let one = tokens[0];
    if (one == "push") {
        if(arr.length < len){
            arr.push(tokens[1]);
        }else console.log('full');
    }
    else if (one == "pop") {
        if (arr.length) {
            console.log(arr.shift());
        } else console.log("empty");
    } else if (one == "front") {
        if (arr.length) {
            console.log(arr[0]);
        } else console.log("empty");
    }else len = parseInt(one);
});

全部评论

相关推荐

05-05 21:45
已编辑
广州大学 Java
点赞 评论 收藏
分享
头像
04-17 09:29
已编辑
湖南农业大学 后端
睡姿决定发型丫:本硕末9也是0offer,简历挂了挺多,只有淘天 美团 中兴给了面试机会,淘天二面挂,美团一面kpi面,中兴一面感觉也大概率kpi(虽然国企,但一面0技术纯聊天有点离谱吧)
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务