作者: _____西班木有蛀牙 | 来源:发表于2018-06-28 01:14 被阅读8次
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>列表</title>
</head>
<body>
    <script>
        function Stack() {
            // 保存栈内元素
            this.dataStore = [];
            // 标记可以插入新元素的位置 栈内压入元素该变量变大 弹出元素 变量变小
            this.top = 0;
            // 入栈操作
            this.push = push;
            // 出栈操作
            this.pop = pop;
            // 返回栈顶元素
            this.peek = peek;
            // 清空栈
            this.clear = clear;
            // 栈的长度
            this.length = length;
        }
        function push(element) {
            this.dataStore[this.top++] = element;
        }
        function pop() {
            return this.dataStore[--this.top];
        }
        function peek() {
            return this.dataStore[this.top - 1];
        }
        function length() {
            return this.top
        }
        function clear() {
            this.top = 0;
        }

        var s = new Stack;
        s.push('小红第一');
        s.push('小李第二');
        s.push('小张第三');
        s.push('小王第四');
        console.log('栈的长度', s.length());
        console.warn('出栈', s.pop());
        console.warn('栈顶', s.peek());
        console.warn('出栈', s.top);
        console.warn('出栈', s.pop());
        console.warn('出栈', s.pop());
        console.warn('栈顶', s.peek());
        console.warn('出栈', s.top);
        // 回文算法 dad 1001 racecar
        // function isPalindrome(word) {
        //     var s = new Stack();
        //     for (var i = 0; i < word.length; i++) {
        //         s.push(word[i]);
        //     }
        //     var rword = "";
        //     console.log(s);
        //     while(s.length() > 0) {
        //         rword += s.pop();
        //     }
        //     console.log(rword);
        //     if (rword == word) {
        //         return true;
        //     } else {
        //         return false;
        //     }
        // }
        // var word = 'racecar';
        // alert(isPalindrome(word));
    </script>
</body>
</html>

相关文章

  • 盏盏天华

    楔子 顾盏从没见过这么漂亮的灯火,仿若满天的鲜花盛开,又像是永不再开。 这样的烟花,总是让她想起那年灯会...

  • 盏盏花苞

    花苞里的露珠 是建盏里的琼酱玉液 一喝就醉 能不能醉倒48年 这纷纷飞樱散落了多少人的梦想 拾起落花 夹在书上 一...

  • 人间灯火盏盏

    遥望人间烟火盏. 秋闻簌落.忽觉微微凉. 难醒大梦.枯枝夕摇曳. 凄凉夜.陌路孤.忆户与猎. 台露良辰江景.知与界...

  • 盏 泥塑火炙之物 成于瓷而优于观 建盏 很多人看不懂,玩不转的东西 却在一些圈子里捧为至宝 很多时候的体验 讲其价...

  • /一盏萧瑟/ 叶落初秋 宿雨褪去 携着丝丝清凉 又是四季 /一盏愁容/ 洒烁余晖 疲倦散漫 沿着白色石子路 家的方...

  • 灯 一盏 微微亮 铅字舞耀 点横撇竖捺 写尽昨日今朝 难悉明时幻莫测 茶 一盏 淡淡香 卷叶渐舒 水滚浸班章 苦涩...

  • 生命的出现消失渺小的如窗外闪烁的灯盏 所以你忧伤的意义何在 海水也曾波澜 可依然流淌 接受吧 原谅吧 不要做让人诧...

网友评论

      本文标题:

      本文链接:https://www.haomeiwen.com/subject/wwewyftx.html