basic logic of speed match

https://github.com/moocstudent/speedMatch

next:
1count down optimize
2symbol canvas file
3score
4control
5music

借用:


// 封装栈类
function Stack(){
    // 栈中的属性
    this.items =[]

    // 栈的相关操作
    // 1.push():将元素压入栈
    //方式一(不推荐):给对象添加方法,其他对象不能复用
    // this.push = () => {
    // }

    //方式二(推荐):给Stack类添加方法,能够多对象复用
    Stack.prototype.push = function(element) {
        // 利用数组item的push方法实现Stack类的pop方法
        this.items.push(element)
    }

    // 2.pop():从栈中取出元素
    Stack.prototype.pop = () => {
        // 利用数组item的pop方法实现Stack类的pop方法
        return this.items.pop()
    }

    // 3.peek():查看一下栈顶元素
    Stack.prototype.peek = () => {
        return this.items[this.items.length - 1]
    }

    // 4.isEmpty():判断栈是否为空
    Stack.prototype.isEmpty = () => {
        // 两个小时的教训啊不是this.length(不是Stack对象的length,Stack类没有length属性啊),而是			Stack类中定义的数组items才有length属性呀
        return this.items.length == 0
    }

    // 5.size():获取栈中元素的个数
    Stack.prototype.size = () => {
        return this.items.length
    }

    // 6.toString():以字符串形式输出栈内数据
    Stack.prototype.toString = () => {
        //希望输出的形式:20 10 12 8 7
        let resultString = ''
        for (let i of this.items){
            resultString += i + ' '
        }
        return resultString
    }
}

posted @   ukyo--碳水化合物  阅读(47)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
历史上的今天:
2020-08-08 1
2020-08-08 reactive和reactor
2020-08-08 today search
2020-08-08 today news 2020-8-8
2019-08-08 单点登录文章集合- demo
2019-08-08 Java HotSpot(TM) 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
2018-08-08 MyBatis基本工作原理
点击右上角即可分享
微信分享提示
主题色彩
神即道,道即法,道法自然,如来。