• 击鼓传花


    首先什么是击鼓传花 ?击鼓传花,也称传彩球。中国民间游戏,流行于中国各地。数人、十数人或数十人围成一个圆圈席地而坐,另外一个人背对着人圈以槌击鼓。鼓响时,开始传花,花由一个人的手里传。人们在击鼓声zhi中传花,鼓声停止到时,花传到谁手上,谁就要“受罚”。而待最终的鼓声落下,无论在谁手中,那花儿总是成了最关注的

    queue.js
     
    class Queue{
        constructor() {
            this.queue = []
        }
        enqueue(element) {
            this.queue.push(element)
            return element
        }
        dequeue() {
            return this.queue.shift()
        }
        front() {
            if(this.queue.length > 0) {
                return this.queue[0]
            } else {
                return undefined
            }
        }
        isEmpty() {
            return this.queue.length > 0
        }
        size() {
            return this.queue.length
        }
    }
     
    在html进行引入
    index.html
    <script src="./queue.js"></script>
        let nameList = ['张三', '李四', '王五', '老六', '老王', '张杰', '八哥', '九叔']
        function pass(nameList, num) {
            let que = new Queue()
            for(let i = 0; i< nameList.length; i++) {
                que.enqueue(nameList[i])
            }
            while(que.size() > 1) {
                for(let i=0; i< num; i++) {
                    que.enqueue(que.dequeue())
                }
                que.dequeue()
            }
            return que.front()
        }
    console.log(pass(nameList,2))

    </script>
  • 相关阅读:
    c语言命名规则 [转载]
    [转贴]C编译过程概述
    [转贴]漫谈C语言及如何学习C语言
    Semaphore源码分析
    如何快速转行大数据
    web前端到底怎么学?
    Code Review怎样做好
    SDK与API的理解
    分析消费者大数据
    程序员的搞笑段子
  • 原文地址:https://www.cnblogs.com/yzy521/p/14146264.html
Copyright © 2020-2023  润新知