列表

作者: 不系流年系乾坤 | 来源:发表于2016-11-07 18:01 被阅读20次

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.coutains = coutains;
}

append给列表添加元素

function append(element){
this.dataStore[this.listSize++] = element;
}

find在列表中查找某一元素

function find(element){
for(var i = 0; i < this.dataStore.length;++i){
if(this.dataStore[i]==element){
return i;
}
}
return -1;
}

remove从列表中删除元素

function remove(element){
var founAt = this.find(element);
if(founAt>-1){
this.dataStore.splice(founAt,1);
--this.listSize;
return true;
}
return false;
}

length列表中有多少个元素

function length(){
return this.listSize;
}

toString显示列表中的元素

function toString(){
return this.dataStore;
}

insert向列表中插入一个元素

function insert(element,after){
//after 插入那个元素后
var insertPos = this.find(after);
if(insert>-1){
this.dataStore.splice(insertPos+1,0,element);
++this.listSize;
return true;
}
return false;
}
}

clear清空列表中所有的元素

function clear(){
delete this.dataStore;
this.dataStore = [];
this.listSize = this.pos = 0;
}

相关文章

  • Markdown 系列(三) 列表

    无序列表 由圆点组成的列表 列表1 列表2 列表3 列表1 列表2 列表3 列表1 列表2 列表3 +-*这三种符...

  • markdown常用的语法

    列表 有序列表: 列表项 1 列表项 2 无序列表: 列表项 1 列表项 2 列表项 3 列表项 4 列表项缩进两...

  • markdown常用语法

    标题 列表 无序列表- 列表1 - 列表1.1 -列表1.2- 列表2 有序列表1. 列表1 1. 列表1....

  • html阶段第二节第一天

    高级标签 列表标签 无序列表 列表一 列表二 ...... 有序列表 列表一 列表二 ...... 定义列表dl...

  • markdown测试

    段落 三级标题 四级标题 五级标题 列表 无序列表 列表1 列表2 列表3 列表1 列表2 列表3 有序列表 列表...

  • 学习小组Day1笔记-Herobrine

    Day1-Herobrine 列表 无序列表 无序列表 无序列表 无序列表 有序列表 有序列表 有序列表 有序列表...

  • H5学习从0到1-H5列表(8)

    列表的基本语法 ol:有序列表 ul:无序列表 li:列表项 dl:列表 dt:列表项 dd:列表描述 常用列表 ...

  • 第一篇简书

    MarkDown首次使用 无序列表 列表1 列表2 列表3 有序列表 有序列表1 有序列表2 有序列表3 有序列表...

  • 标题

    列表1 列表2 子列表1 子列表2 子列表3子子列表1子子列表2子子子列表1子子子列表2

  • markdown test

    header2 test> test 列表* 列表2 * 列表2.1 列表列表2列表2.1

网友评论

      本文标题:列表

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