跳转到内容
View in the app

A better way to browse. Learn more.

彼岸论坛

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
欢迎抵达彼岸 彼岸花开 此处谁在 -彼岸论坛

[分享创造] 分享一个自娱自乐造的中文脚本语言

发表于

链接: https://github.com/4ra1n/y4-lang

使用 golang 标准库,造的一个轮子,尽量不适用任何第三方库,主要目的是学习和娱乐

快排示例

函数 交换(数组, 甲, 乙) {
    临时 = 数组[甲];
    数组[甲] = 数组[乙];
    数组[乙] = 临时;
}

函数 分区(数组, 低位, 高位) {
    目标 = 数组[高位];
    甲 = 低位 - 1;
    循环 乙=低位; 乙<高位; 乙=乙+1 {
        如果 数组[乙] < 目标 {
            甲 = 甲 + 1;
            交换(数组, 甲, 乙);
        }
    }
    交换(数组, 甲 + 1, 高位);
    返回 甲 + 1;
}

函数 快排(数组, 低位, 高位) {
    如果 低位 < 高位 {
        目标 = 分区(数组, 低位, 高位);
        快排(数组, 低位, 目标-1);
        快排(数组, 目标+1, 高位);
    }
}

函数 主函数() {
    数组 = [10, 7, 8, 9, 1, 5, 666, 888, 10000, -50];
    数组长 = 长度(数组);
    快排(数组, 0, 数组长-1);
    打印(数组)
}

运行截图:

001.png

参考了《两周自制脚本语言》

原书使用 Java 且包含了一些作者自己写的库,我用 Golang 从头开始实现了功能

Featured Replies

No posts to show

创建帐户或登录来提出意见

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.