Daily English - 2015/02/02 – 算法(结构)

/* queue FIFO

        */
        (function () {
            var queue = [‘a‘, ‘b‘, ‘c‘, ‘d‘, ‘e‘, ‘f‘, ‘g‘, ‘h‘, ‘i‘, ‘j‘, ‘k‘],
                iHead = 0, iTail = queue.length,
                result = [];

            while (iHead !== iTail) {
                result.push(queue[iHead]);
                queue[iHead] = null;
                iHead++;
                //if (iHead === iTail) {
                //    break;
                //}
                queue[iTail] = (queue[iHead]);
                iHead++;
                iTail++;
            }
            console.log(result.join(", "));

        }());
/* stack LIFO

        */
        (function () {
            var stack1 = [], stack2 = [], top1 = -1, top2 = -1,
                hash = { "{": "}", "[": "]", "(": ")" }, result = [], vl, vr;

            stack1 = ["{", "[", "(", ")", "(", ")", "]", "[", "(", ")", "]", "(", ")", "}"];
            top1 = stack1.length - 1;
            while (top1 >= 0) {
                vl = stack1[top1--];
                switch (vl) {
                    case "{":
                    case "[":
                    case "(":
                        vr = top2 >= 0 ? stack2[top2--] : "undefined";
                        if (hash[vl] !== vr) {
                            console.log("Error: " + vl + " !== " + vr);
                            return;
                        }
                        else {
                            result.push([vl, vr]);
                        }
                        break;
                    case "}":
                    case "]":
                    case ")":
                        stack2[++top2] = vl;
                        break;
                }
            }
            if (top2 >= 0) {
                console.log("Error: Don‘t find out the same sign: " + stack2.slice(0, top2 + 1).join(", "));
            } else {
                console.log(result.join(", "));
            }
        }());
/* chain table
           数组模拟链表:两个数组,一个数组存相应值,一个数组存相对应索引处值得下一个值得索引,即索引表
        */
        (function () {
            var Node = function (value, nextNode) {
                this.value = value;
                this.nextNode = nextNode;
            };

            var chain = new Node(1, new Node(3, new Node(5, new Node(7, new Node(9, null))))),
                fnInsert = function (value, node) {
                    if (!node.nextNode || node.nextNode.value >= value) {
                        node.nextNode = new Node(value, node.nextNode);
                        return;
                    }
                    else {
                        fnInsert(value, node.nextNode);
                    }
                },
                fnPrint = function (node) {
                    return [node.value].concat(!!node.nextNode ? fnPrint(node.nextNode) : []);
                };

            //insert
            console.log(fnPrint(chain));
            var insertValue = 6;
            fnInsert(6, chain);

            console.log(fnPrint(chain));
        }());
时间: 2024-08-07 19:23:26

Daily English - 2015/02/02 – 算法(结构)的相关文章

Daily English - 2015/01/30 – 算法(排序)

(function () { /* 通排序 最快最简单的排序 */ var data = [100, 50, 75, 25, 1, 20, 90, 30, 80, 40, 60, 50], result = [], barrel = [], i, j, item; //初始化桶 m = 桶数 for (i = 0; i < 101; i++) { barrel[i] = 0; } //插入桶 n = 排序数的个数 for (i = 0; item = data[i]; i++) { barrel

2015.11.02 学习 Ubuntu下安装gosublime插件及其配置

2015.11.02 学习 Ubuntu下安装gosublime插件及其配置 1.Ctrl+shift+P 打开package control 输入pcip 回车 2.出现的框中输入gosublime,回车 3.preferences---package setting--gosublime--setting default 打开后在env{}中添加GOROOT和GOPATH 4.保存后全部复制到preferences---package setting--gosublime--setting

JavaScript权威指南第02章 词法结构

词法结构 2.1字符集 JavaScript 是Unicode字符集编写,几乎支持地球上所有的语言. 2.1.1区分大小写 javascript是区分大小写的语言. 2.1.2 空格.换行符和格式控制符 javascript会忽略标识之间的空格符.换行符.通过空格和换行可以大大地提高代码的可读性.当需要使用空格和换行符时,使用Unicode的转义来实现. 2.2注释 单行注释     //这里是单行注释 多行注释    /**多行注释 */ 2.3直接量 在程序中能够直接使用的量,比如数字,字符

【转换博客通知】(本博客2015.08.02停用)

2015.08.02 本博客停用,搬运至 http://tonyfang.is-programmer.com/ 感谢各位对我的支持!

利用jTessBoxEditor工具进行Tesseract3.02.02样本训练,提高验证码识别率,tesseract训练样本

http://www.bkjia.com/Pythonjc/1131343.html 利用jTessBoxEditor工具进行Tesseract3.02.02样本训练,提高验证码识别率,tesseract训练样本 1.背景 前文已经简要介绍tesseract ocr引擎的安装及基本使用,其中提到使用-l eng参数来限定语言库,可以提高识别准确率及识别效率. 本文将针对某个网站的验证码进行样本训练,形成自己的语言库,来提高验证码识别率. 2.准备工具 tesseract样本训练有一个官方流程说明

2015 年 JXNU_ACS 算法组寒假第二次周赛

2015 年 JXNU_ACS 算法组寒假第二次周赛 比赛链接:http://acm.hdu.edu.cn/diy/contest_show.php?cid=26246 Start Time : 2015-02-01 13:00:00 End Time : 2015-02-01 17:30:00 终榜:http://acm.hdu.edu.cn/diy/contest_ranklist.php?cid=26246&page=1 这次比赛考查的知识都很基础,甚至还有几道就是C语言基础(比如1006

Daily English words study

detect 发现 察觉 workstation 工作站/计算机 proceed vi 进行 继续 abort  n 中止计划 vi/vt 流产 发育不全 使-流产 security 安全 guideline 指导 enhancement 增强 interface 接口 definition 清晰度 multmedia 多媒体 prompt adj/vi/vt 敏捷的 推进 鼓励 startup n 启动 procedure n 程序 步骤 手续 instant 立即 瞬间 coarse 粗糙的

Coach Shane&#39;s Daily English Dictation 1-4

1.Mother Teresa, who received a Nobel Peace Prize for her work on behalf of the poor dies in Calcutta, India--she was 87 years old. note: 1.on 读做/∂n/ 而不是 /on/ 2.主句谓语dies应使用过去时,但是由于文章的视角是跟随Mother Teresa的人生进程,因此使用一般现在时. 2.Jerry,what time do you have? I

Coach Shane&#39;s Daily English Dictaion 6-10

6.the secret of life is just to live every monent. notes: 1.just不读/t/,可以看成juss. 7.another rogue trader has cost a bank billions. notes: 1.rogue:混蛋. 2.trader:商人. 3.sost a连读,变成/kost∂/. 4.billions后面省略了of dollar. 8. German,Rolf Buchholz is the  man with