SOURCE

// listSize(属性) 列表的元素个数
// pos (属性) 列表的当前位置
// length (属性) 返回列表中元素的个数
// clear (方法) 清空列表中的所有元素
// toString (方法) 返回列表的字符串形式
// getElement (方法) 返回当前位置的元素
// insert (方法) 在现有元素后插入新元素
// append (方法) 在列表的末尾添加新元素
// remove (方法) 从列表中删除元素
// front (方法) 将列表的当前位置设移动到第一个元素
// end (方法) 将列表的当前位置移动到最后一个元素
// prev(方法) 将当前位置后移一位
// next (方法) 将当前位置前移一位
// currPos (方法) 返回列表的当前位置
// moveTo(方法) 将当前位置移动到指定位置
function List(){
    this.listSize = 0 //当前列表的大小
    this.pos = 0 //当前列表指针
    this.dataStore = [] //数据
    this.clear = clear;  //清空列表
    this.find = find;    //寻找指定值
    this.toString = toString;    //字符串化
    this.insert = insert;    //插入
    this.append = append;    //追击
    this.remove = remove;    //删除
    this.front = front;  //指针首位
    this.end = end;    //指针末尾
    this.prev = prev;    //上个节点
    this.next = next;    //下个节点
    this.length = length;    //列表大小
    this.currPos = currPos; //当前节点   
    this.moveTo = moveTo;   // 
    this.getElement = getElement;    //获取当前节点的值
    this.contains = contains;
}
function print(){
    this.dataStore.map(item=>console.log(item))
}
function toString(){
    return this.dataStore.toString();
}
function append(val){
    this.dataStore[this.listSize++] = val
}
function remove(val){
    if(this.find(val)!==-1){
        this.dataStore.splice(this.find(val),1) 
        this.listSize--
        return true
    }
    return false
}
function find(val){
    for(let i = 0 ;i<this.dataStore.length;i++){
        if(this.dataStore[i] === val){
            return i
        }
    }
    return -1
}
function length(){
    return this.listSize
}

function insert(val,after){
    let afterIndex = this.find(after)
    if(afterIndex > -1){
        this.dataStore.splice(afterIndex + 1,0,val)
        this.dataStore.length++
        return true
    }
    return false 
}

function clear(){
    this.dataStore = []
    this.listSize = 0
    this.pos = 0
}
function contains(val){
     for(let i = 0 ;i<this.dataStore.length;i++){
        if(this.dataStore[i] === val){
            return true
        }
    }
    return false
}
function currPos(){
    return this.pos
}
function front(){
    this.pos = 0
}
function end(){
    this.pos = this.listSize - 1 
}
function prev(){
    if(this.pos>0){
        this.prev--
    }
}
function next(){
    if(this.pos <this.listSize - 1 ){
        this.pos++
    }
}
function getElement(){
    return this.dataStore[this.pos]
}
function moveTo(index){
    if(index<0 || index>this.listSize - 1){
        return 
    }
    this.pos = index
    return this.dataStore[index]
}
//迭代器
function diedaiqi(){
    for(this.currPos();this.currPos()<this.end();this.next()){
        print(this.getElement())
    }
    for(this.end();this.currPos()>=0;this.prev()){
        print(this.getElement())
    }
}

function insertVal(nums,val){
    if(nums.every(item=>item<val)){
        nums.push(val)
    }
}
//book person bookPersonOP
function BookPersonOP(){
    this.book = []
    this.preson = []
    this.bookPersonOP = {'hyh':['232']}
}
console 命令行工具 X clear

                    
>
console