• 遍历列表


        function List() {
            this.listSize = 0;//列表的元素个数,属性
            this.pos = 0;//列表的当前位置,属性
            this.dataStore = []; // 初始化一个空数组来保存列表元素
    
            this.append = append;//在列表的末尾添加新元素,方法
    
            this.front = front;//将列表的当前位置设移动到第一个元素,方法
            this.end = end;//将列表的当前位置移动到最后一个元素,方法
            this.prev = prev;//将当前位置前移一位,方法
            this.next = next;//将当前位置后移一位,方法
            this.moveTo = moveTo;//将当前位置移动到指定位置,方法
    
            this.currPos = currPos;//返回列表的当前位置,方法    
            this.getElement = getElement;//返回当前位置的元素,方法
        }
        function append(element) {
            this.dataStore[this.listSize++] = element;
            //后自加,在新位置添加元素,同时列表的元素个数加1
        }
    
        function front() {
            this.pos = 0;
        }
        function end() {
            this.pos = this.listSize - 1;
        }
        function prev() {
            if (this.pos > 0) {
                --this.pos;
            }
        }
        function next() {
            if (this.pos < this.listSize - 1) {
                ++this.pos;
            }
        }
        function moveTo(position) {
            this.pos = position;
        }
    
        function currPos() {
            return this.pos;
        }
        function getElement() {
            return this.dataStore[this.pos];
        }
    
        var names = new List();
        names.append("Clayton");
        names.append("Raymond");
        names.append("Cynthia");
        names.front();
        alert(names.getElement()); // 显示 Clayton
  • 相关阅读:
    Python操作Excel
    unittest单元测试生成HTML测试报告
    pycharm安装 package报错:module 'pip' has no attribute 'main'
    Jenkins关闭、重启,Jenkins服务的启动、停止方法。
    selenium如何获取已定位元素的属性值?
    本周学习小结(23/03
    本周学习小结(16/03
    本周学习小结(09/03
    本周学习小结(02/03
    本周学习小结(24/02
  • 原文地址:https://www.cnblogs.com/feile/p/5371171.html
Copyright © 2020-2023  润新知