zoukankan      html  css  js  c++  java
  • JavaScript List

    function List() {
        this.listSize = 0;
        this.pos = 0;
        this.dataSource = [];
        this.clear = function() {
            this.dataSource = [];
            this.pos = 0;
            this.listSize = 0;
        };
        this.find = function(item) {
            for (var i = this.dataSource.length - 1; i >= 0; i--) {
                if (this.dataSource[i] === item) {
                    return i;
                }
            };
            return -1;
        }
        this.toString = function() {
            return this.dataSource;
        };
        this.insert = function(item) {
            var insertPos = this.find(item);
            if (insertPos > -1) {
                this.dataSource.splice(insertPos + 1, 0, item);
                ++this.listSize;
                return true;
            }
            return false;
        };
        this.append = function(item) {
            this.dataSource[this.listSize++] = item;
        };
        this.remove = function(item) {
            var foundAt = this.find(item);
            if (foundAt > -1) {
                this.dataSource.splice(foundAt, 1);
                --this.listSize;
                return true;
            }
            return false;
        };
        this.front = function() {
            this.pos = 0;

        };
        this.end = function() {
            this.pos = this.listSize - 1;
        };
        this.prev = function() {
            if (this.pos > 0) {
                --this.pos;
            }
        };
        this.next = function() {
            if (this.pos < this.listSize - 1) {
                ++this.pos;
            }
        };
        this.length = function() {
            return this.listSize;
        };
        this.currPos = function() {
            return this.pos;
        };
        this.moveTo = function(position) {
            this.pos = position;
        };
        this.getElement = function() {
            return this.dataSource[this.pos];
        };
        this.contains = function(item) {
            for (var i = this.dataSource.length - 1; i >= 0; i--) {
                if (this.dataSource[i] === item) {
                    return true;
                }

            };
            return false;
        };
    }


    var list = new List();
    list.append("shidengyun");
    list.append("zhujing");
    list.append("shidengyun");
    list.append("zhujing");

    console.log(list.toString());
    console.log('-------------');

    list.insert("shidengyun");

    console.log(list.toString());
    console.log('-------------');

    list.remove("zhujing");
    console.log(list.toString());
    console.log('-------------');

    list.front();
    console.log(list.getElement());
    list.next();
    console.log(list.getElement());
    list.prev();
    console.log(list.getElement());
    console.log('-------------');
    for (list.front(); list.currPos < list.length(); list.next()) {
        console.log(list.getElement());
    }
    console.log('-------------');
    for (list.end(); list.currPos >= 0; list.prev()) {
        console.log(list.getElement());
    }
    View Code
  • 相关阅读:
    frida hook native -- frida hook so层 实例代码讲解
    frida hook 类所有方法(ZenTracker)
    frida hook AES DES RSA 自吐算法
    frida java层和c层打印堆栈 (修复优化)
    frida延时hook的3种方法
    [去广告]x米万能遥控 去掉底部banner广告
    Linux使用C语言连接MYSQL
    Linux一对一通信(UDP)
    Linux一对多的通信
    Linux一对一的通信
  • 原文地址:https://www.cnblogs.com/shidengyun/p/5153130.html
Copyright © 2011-2022 走看看