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

【模板】循环队列

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

const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;

void (async function () {
    // Write your code here
    let line1 = (await readline()).split(" ").map(Number);
    let arrLenMax = line1[0];
    let len = line1[1];
    let arr = [];
    let obj = {
        push: (n) => {
            if (arr.length < arrLenMax) {
                arr.push(n);
            } else {
                console.log("full");
            }
        },
        pop: () => {
            if (!arr.length) {
                console.log("empty");
            } else {
                console.log(arr.shift());
            }
        },
        front: () => {
            if (!arr.length) {
                console.log("empty");
            } else {
                console.log(arr[0]);
            }
        },
    };
    for (let i = 0; i < len; i++) {
        let line = (await readline()).split(' ');
        let type=line[0];
        type ==='push'?obj[type](line[1]):obj[type]()
        
    }
})();

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务